summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Mitchell <rtmitchell@google.com>2018-05-30 12:17:01 -0700
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-08-10 20:28:02 +0000
commit906afb4f3641963583a4334bd8291d479b8c844a (patch)
tree57d752c537c3af25a31f9906f50d409c0e3166c6
parent92aed32dda0a6bec5cd26f4f32d8c9b103af557b (diff)
downloadbase-906afb4f3641963583a4334bd8291d479b8c844a.tar.gz
Fix DynamicRefTable::load security bug
DynamicRefTables parsed from apks are missing bounds checks that prevent buffer overflows. This changes verifies the bounds of the header before attempting to preform operations on the chunk. Bug: 79488511 Test: run cts -m CtsAppSecurityHostTestCases \ -t android.appsecurity.cts.CorruptApkTests Change-Id: I02c8ad957da244fce777ac68a482e4e8fa70f846 Merged-In: I02c8ad957da244fce777ac68a482e4e8fa70f846 (cherry picked from commit 18a6ada4aa136da4f50f03fff91d61d448ced195)
-rw-r--r--libs/androidfw/ResourceTypes.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/libs/androidfw/ResourceTypes.cpp b/libs/androidfw/ResourceTypes.cpp
index c78554f340fc..4813b4c83d04 100644
--- a/libs/androidfw/ResourceTypes.cpp
+++ b/libs/androidfw/ResourceTypes.cpp
@@ -6576,8 +6576,16 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg,
}
} else if (ctype == RES_TABLE_LIBRARY_TYPE) {
+
if (group->dynamicRefTable.entries().size() == 0) {
- status_t err = group->dynamicRefTable.load((const ResTable_lib_header*) chunk);
+ const ResTable_lib_header* lib = (const ResTable_lib_header*) chunk;
+ status_t err = validate_chunk(&lib->header, sizeof(*lib),
+ endPos, "ResTable_lib_header");
+ if (err != NO_ERROR) {
+ return (mError=err);
+ }
+
+ err = group->dynamicRefTable.load(lib);
if (err != NO_ERROR) {
return (mError=err);
}