diff options
| author | Brian Carlstrom <bdc@google.com> | 2014-01-24 18:23:57 +0000 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2014-01-24 18:23:57 +0000 |
| commit | 722357738fd8dea75d147dbc8d8d59c72c7ec7dd (patch) | |
| tree | 09ea5a6603c8161aa3e03bcf441da3e4136a574e /libziparchive/zip_archive_test.cc | |
| parent | c7e28899c3917ad6e72d5dc99401bcd133cbd475 (diff) | |
| parent | e18df357a4f8e3e960cca4ae281d3fe2f3e4b2c0 (diff) | |
| download | system_core-722357738fd8dea75d147dbc8d8d59c72c7ec7dd.zip system_core-722357738fd8dea75d147dbc8d8d59c72c7ec7dd.tar.gz system_core-722357738fd8dea75d147dbc8d8d59c72c7ec7dd.tar.bz2 | |
am e18df357: am 794b587b: Merge "Fix entry handling for 0 length entries."
* commit 'e18df357a4f8e3e960cca4ae281d3fe2f3e4b2c0':
Fix entry handling for 0 length entries.
Diffstat (limited to 'libziparchive/zip_archive_test.cc')
| -rw-r--r-- | libziparchive/zip_archive_test.cc | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/libziparchive/zip_archive_test.cc b/libziparchive/zip_archive_test.cc index 022be5b..3082216 100644 --- a/libziparchive/zip_archive_test.cc +++ b/libziparchive/zip_archive_test.cc @@ -140,8 +140,45 @@ TEST(ziparchive, ExtractToMemory) { CloseArchive(handle); } +TEST(ziparchive, EmptyEntries) { + char temp_file_pattern[] = "empty_entries_test_XXXXXX"; + int fd = mkstemp(temp_file_pattern); + ASSERT_NE(-1, fd); + const uint32_t data[] = { + 0x04034b50, 0x0000000a, 0x63600000, 0x00004438, 0x00000000, 0x00000000, + 0x00090000, 0x6d65001c, 0x2e797470, 0x55747874, 0x03000954, 0x52e25c13, + 0x52e25c24, 0x000b7875, 0x42890401, 0x88040000, 0x50000013, 0x1e02014b, + 0x00000a03, 0x60000000, 0x00443863, 0x00000000, 0x00000000, 0x09000000, + 0x00001800, 0x00000000, 0xa0000000, 0x00000081, 0x706d6500, 0x742e7974, + 0x54557478, 0x13030005, 0x7552e25c, 0x01000b78, 0x00428904, 0x13880400, + 0x4b500000, 0x00000605, 0x00010000, 0x004f0001, 0x00430000, 0x00000000 }; + const ssize_t file_size = 168; + ASSERT_EQ(file_size, TEMP_FAILURE_RETRY(write(fd, data, file_size))); + + ZipArchiveHandle handle; + ASSERT_EQ(0, OpenArchiveFd(fd, "EmptyEntriesTest", &handle)); + + ZipEntry entry; + ASSERT_EQ(0, FindEntry(handle, "empty.txt", &entry)); + ASSERT_EQ(static_cast<uint32_t>(0), entry.uncompressed_length); + uint8_t buffer[1]; + ASSERT_EQ(0, ExtractToMemory(handle, &entry, buffer, 1)); + + char output_file_pattern[] = "empty_entries_output_XXXXXX"; + int output_fd = mkstemp(output_file_pattern); + ASSERT_NE(-1, output_fd); + ASSERT_EQ(0, ExtractEntryToFile(handle, &entry, output_fd)); + + struct stat stat_buf; + ASSERT_EQ(0, fstat(output_fd, &stat_buf)); + ASSERT_EQ(0, stat_buf.st_size); + + close(fd); + close(output_fd); +} + TEST(ziparchive, ExtractToFile) { - char kTempFilePattern[] = "zip_archive_test_XXXXXX"; + char kTempFilePattern[] = "zip_archive_input_XXXXXX"; int fd = mkstemp(kTempFilePattern); ASSERT_NE(-1, fd); const uint8_t data[8] = { '1', '2', '3', '4', '5', '6', '7', '8' }; |
