summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2017-04-20 22:37:43 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-04-20 22:37:55 +0000
commitff89e2be75d6bc9152a1e64bd250dda19a913658 (patch)
treea1bcb3bcb6850c0ea9cc4a29ada23b55acdd55e9
parent879c55ba74b58d528c3ba1bfe422826353d9f424 (diff)
parentfd1574b915835e95eb1251df66b778aa8db62385 (diff)
Merge "Fix out of bound read in libziparchive" into snap-temp-L07900000056674784
-rw-r--r--libziparchive/zip_archive.cc13
1 files changed, 8 insertions, 5 deletions
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index 986ee7208..49097ce9b 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -386,6 +386,14 @@ static int32_t ParseZipArchive(ZipArchive* archive) {
const uint8_t* const cd_end = cd_ptr + cd_length;
const uint8_t* ptr = cd_ptr;
for (uint16_t i = 0; i < num_entries; i++) {
+ if (ptr > cd_end - sizeof(CentralDirectoryRecord)) {
+ ALOGW("Zip: ran off the end (at %" PRIu16 ")", i);
+#if defined(__ANDROID__)
+ android_errorWriteLog(0x534e4554, "36392138");
+#endif
+ return -1;
+ }
+
const CentralDirectoryRecord* cdr =
reinterpret_cast<const CentralDirectoryRecord*>(ptr);
if (cdr->record_signature != CentralDirectoryRecord::kSignature) {
@@ -393,11 +401,6 @@ static int32_t ParseZipArchive(ZipArchive* archive) {
return -1;
}
- if (ptr + sizeof(CentralDirectoryRecord) > cd_end) {
- ALOGW("Zip: ran off the end (at %" PRIu16 ")", i);
- return -1;
- }
-
const off64_t local_header_offset = cdr->local_file_header_offset;
if (local_header_offset >= archive->directory_offset) {
ALOGW("Zip: bad LFH offset %" PRId64 " at entry %" PRIu16,