From d1ba38f7c96e74901779089fea6d09b0c7c2521d Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Thu, 17 Sep 2020 11:32:29 -0400 Subject: Check for overflow before allocating memory fore decompression. On 32bit devices, an ZipEntry64 may have size > 2^32, we should check for such cases before attempting to allocate memory. Test: mm -j Change-Id: I0f916ef4b2a692f167719a74bd6ff2e887c6c2ce --- install/verifier.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'install/verifier.cpp') diff --git a/install/verifier.cpp b/install/verifier.cpp index d8bc53f69..3f0260138 100644 --- a/install/verifier.cpp +++ b/install/verifier.cpp @@ -323,6 +323,12 @@ static std::vector IterateZipEntriesAndSearchForKeys(const ZipArchi std::string_view name; ZipEntry64 entry; while ((iter_status = Next(cookie, &entry, &name)) == 0) { + if (entry.uncompressed_length > std::numeric_limits::max()) { + LOG(ERROR) << "Failed to extract " << name + << " because's uncompressed size exceeds size of address space. " + << entry.uncompressed_length; + return {}; + } std::vector pem_content(entry.uncompressed_length); if (int32_t extract_status = ExtractToMemory(handle, &entry, pem_content.data(), pem_content.size()); -- cgit v1.2.3