summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNarayan Kamath2017-09-14 04:41:28 -0500
committerNarayan Kamath2017-09-20 10:22:46 -0500
commiteeb93c9a6434af7caabef9b4bb3aa54ad3b50e2a (patch)
tree65514337a8d53b789c82705a83662ae1036f2b7c
parent4732ec64403360d1b53418e06b422516faf5da49 (diff)
downloadplatform-system-core-eeb93c9a6434af7caabef9b4bb3aa54ad3b50e2a.tar.gz
platform-system-core-eeb93c9a6434af7caabef9b4bb3aa54ad3b50e2a.tar.xz
platform-system-core-eeb93c9a6434af7caabef9b4bb3aa54ad3b50e2a.zip
DO NOT MERGE : Fix build breakage due to 2d516d2d46b1b1.
Test: make Test: zip_archive_test Bug: 64211847 (cherry picked from commit 547c7d9a0b6651ace0ade7849661ba6c20770ae6) (cherry picked from commit bfe4b5edb3097df66ddbf9639c3b3cd290734ed8) Change-Id: Ide48ce66542e152d88520dcd6abcd104e48137f6
-rw-r--r--libziparchive/zip_archive.cc6
-rw-r--r--libziparchive/zip_archive_test.cc16
2 files changed, 14 insertions, 8 deletions
diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc
index d0ba3d48f..7cc9ac39d 100644
--- a/libziparchive/zip_archive.cc
+++ b/libziparchive/zip_archive.cc
@@ -594,6 +594,8 @@ static int32_t MapCentralDirectory(int fd, const char* debug_file_name,
594 return result; 594 return result;
595} 595}
596 596
597static inline ssize_t ReadAtOffset(int fd, uint8_t* buf, size_t len, off64_t off);
598
597/* 599/*
598 * Parses the Zip archive's Central Directory. Allocates and populates the 600 * Parses the Zip archive's Central Directory. Allocates and populates the
599 * hash table. 601 * hash table.
@@ -672,8 +674,8 @@ static int32_t ParseZipArchive(ZipArchive* archive) {
672 } 674 }
673 675
674 uint32_t lfh_start_bytes; 676 uint32_t lfh_start_bytes;
675 if (!archive->mapped_zip.ReadAtOffset(reinterpret_cast<uint8_t*>(&lfh_start_bytes), 677 if (ReadAtOffset(archive->fd, reinterpret_cast<uint8_t*>(&lfh_start_bytes),
676 sizeof(uint32_t), 0)) { 678 sizeof(uint32_t), 0) != sizeof(uint32_t)) {
677 ALOGW("Zip: Unable to read header for entry at offset == 0."); 679 ALOGW("Zip: Unable to read header for entry at offset == 0.");
678 return -1; 680 return -1;
679 } 681 }
diff --git a/libziparchive/zip_archive_test.cc b/libziparchive/zip_archive_test.cc
index 4088843f9..2ae49a22b 100644
--- a/libziparchive/zip_archive_test.cc
+++ b/libziparchive/zip_archive_test.cc
@@ -266,7 +266,7 @@ TEST(ziparchive, ExtractToFile) {
266// Manual changes : 266// Manual changes :
267// [2] = 0xff // Corrupt the LFH signature of entry 0. 267// [2] = 0xff // Corrupt the LFH signature of entry 0.
268// [3] = 0xff // Corrupt the LFH signature of entry 0. 268// [3] = 0xff // Corrupt the LFH signature of entry 0.
269static const std::vector<uint8_t> kZipFileWithBrokenLfhSignature{ 269static const uint8_t kZipFileWithBrokenLfhSignature[] = {
270 //[lfh-sig-----------], [lfh contents--------------------------------- 270 //[lfh-sig-----------], [lfh contents---------------------------------
271 0x50, 0x4b, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x80, 271 0x50, 0x4b, 0xff, 0xff, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x77, 0x80,
272 //-------------------------------------------------------------------- 272 //--------------------------------------------------------------------
@@ -297,12 +297,16 @@ static const std::vector<uint8_t> kZipFileWithBrokenLfhSignature{
297 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00}; 297 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00};
298 298
299TEST(ziparchive, BrokenLfhSignature) { 299TEST(ziparchive, BrokenLfhSignature) {
300 TemporaryFile tmp_file; 300 char kTempFilePattern[] = "zip_archive_input_XXXXXX";
301 ASSERT_NE(-1, tmp_file.fd); 301 int fd = make_temporary_file(kTempFilePattern);
302 ASSERT_TRUE(android::base::WriteFully(tmp_file.fd, &kZipFileWithBrokenLfhSignature[0], 302 ASSERT_NE(-1, fd);
303 kZipFileWithBrokenLfhSignature.size())); 303
304 ASSERT_EQ(static_cast<int32_t>(sizeof(kZipFileWithBrokenLfhSignature)),
305 TEMP_FAILURE_RETRY(write(fd, kZipFileWithBrokenLfhSignature,
306 sizeof(kZipFileWithBrokenLfhSignature))));
304 ZipArchiveHandle handle; 307 ZipArchiveHandle handle;
305 ASSERT_EQ(-1, OpenArchiveFd(tmp_file.fd, "LeadingNonZipBytes", &handle)); 308 ASSERT_EQ(-1, OpenArchiveFd(fd, "LeadingNonZipBytes", &handle));
309 close(fd);
306} 310}
307 311
308int main(int argc, char** argv) { 312int main(int argc, char** argv) {