summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Joseph Avila <tavila@google.com>2017-05-16 16:40:36 -0700
committerThomas Joseph Avila <tavila@google.com>2017-05-16 16:40:36 -0700
commit4e65f03beb300e92b8692c01ead91f2aec2e4cf5 (patch)
tree044e687a8964cd04ff21719e15b950edea4deb26
parentd7db96226a035d24af53aa98c16e11d34b24d286 (diff)
parentf011398da5c70297c74b4120a8b14856ff4684d1 (diff)
downloadcore-linaro-m-gcc7.tar.gz
Merge remote-tracking branch 'goog/security-aosp-mnc-mr1-release' into HEADandroid-6.0.1_r81android-6.0.1_r80marshmallow-mr2-releaselinaro-m-gcc7
-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 a17091f95..8c2c559b1 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -580,6 +580,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) {
@@ -587,11 +595,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,