Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e170e387 authored by Tianjie Xu's avatar Tianjie Xu Committed by android-build-merger
Browse files

Fix out of bound read in libziparchive am: d9fd1863 am: 69089964 am:...

Fix out of bound read in libziparchive am: d9fd1863 am: 69089964 am: 25c0d68d am: ed33065b am: bc8c8e4b am: afddaba0 am: 0b1ad230 am: d4b4f0a1
am: 2aea56db

Change-Id: Ib2eebcb64ffb95737ef4a739dddf181dcdaa9fae
parents 91e3f638 2aea56db
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -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,