diff options
author | Tianjie Xu <xunchang@google.com> | 2017-04-05 14:46:27 -0700 |
---|---|---|
committer | gitbuildkicker <android-build@google.com> | 2017-04-19 11:00:40 -0700 |
commit | 5cc86661c6ecf17104f338ea767e878c502f8a73 (patch) | |
tree | fb05e74e6a631650673667b12361ccfb0f2be29a | |
parent | 7f94bb41fc93ae784f6e01ef63ff1daf5a531122 (diff) | |
download | core-nougat-mr1.7-release.tar.gz |
Fix out of bound read in libziparchiveandroid-7.1.1_r57android-7.1.1_r56android-7.1.1_r55android-7.1.1_r52android-7.1.1_r50android-7.1.1_r48android-7.1.1_r45android-7.1.1_r42nougat-mr1.7-releasenougat-mr1.6-releasenougat-mr1.5-release
We should check the boundary of central directory before checking its
signature. Swap the order of these two checks.
Bug: 36392138
Test: libziparchive doesn't read the signature after boundary check fails.
Change-Id: Ie89f709bb2d1ccb647116fb7ccb1e23c943e5ab8
(cherry picked from commit 74464a1361562d4042a67c5d66bfcf396ee7e59c)
(cherry picked from commit d9fd1863f46d5185eaaebc0803ee9c5da3ef110b)
-rw-r--r-- | libziparchive/zip_archive.cc | 13 |
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, |