diff options
| author | Tim Kientzle <kientzle@FreeBSD.org> | 2008-08-10 05:00:14 +0000 |
|---|---|---|
| committer | Tim Kientzle <kientzle@FreeBSD.org> | 2008-08-10 05:00:14 +0000 |
| commit | fb8056b49a0df3665d8f5c090c23abbed63dbb93 (patch) | |
| tree | be3dff788d5455104dbcbee2ddcb6813ff95790a /lib/libarchive | |
| parent | 87ec343af7d2d8c4806a164ae9dd48ae2e7d8d6e (diff) | |
Notes
Diffstat (limited to 'lib/libarchive')
| -rw-r--r-- | lib/libarchive/archive_read_support_format_zip.c | 20 | ||||
| -rw-r--r-- | lib/libarchive/test/test_read_format_zip.c | 7 | ||||
| -rw-r--r-- | lib/libarchive/test/test_read_format_zip.zip.uu | 6 |
3 files changed, 22 insertions, 11 deletions
diff --git a/lib/libarchive/archive_read_support_format_zip.c b/lib/libarchive/archive_read_support_format_zip.c index 1ea19ab37ce2..e64c62c0c950 100644 --- a/lib/libarchive/archive_read_support_format_zip.c +++ b/lib/libarchive/archive_read_support_format_zip.c @@ -53,6 +53,9 @@ struct zip { int64_t entry_compressed_bytes_read; int64_t entry_uncompressed_bytes_read; + /* Running CRC32 of the decompressed data */ + unsigned long entry_crc32; + unsigned version; unsigned system; unsigned flags; @@ -70,7 +73,7 @@ struct zip { char end_of_entry; char end_of_entry_cleanup; - long crc32; + unsigned long crc32; ssize_t filename_length; ssize_t extra_length; int64_t uncompressed_size; @@ -299,6 +302,7 @@ archive_read_format_zip_read_header(struct archive_read *a, zip->end_of_entry_cleanup = 0; zip->entry_uncompressed_bytes_read = 0; zip->entry_compressed_bytes_read = 0; + zip->entry_crc32 = crc32(0, NULL, 0); if ((h = __archive_read_ahead(a, 4)) == NULL) return (ARCHIVE_FATAL); @@ -523,14 +527,13 @@ archive_read_format_zip_read_data(struct archive_read *a, "ZIP uncompressed data is wrong size"); return (ARCHIVE_WARN); } -/* TODO: Compute CRC. */ -/* - if (zip->crc32 != zip->entry_crc32_calculated) { + /* Check computed CRC against header */ + if (zip->crc32 != zip->entry_crc32) { archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC, - "ZIP data CRC error"); + "ZIP bad CRC: 0x%lx should be 0x%lx", + zip->entry_crc32, zip->crc32); return (ARCHIVE_WARN); } -*/ /* End-of-entry cleanup done. */ zip->end_of_entry_cleanup = 1; } @@ -570,6 +573,11 @@ archive_read_format_zip_read_data(struct archive_read *a, } break; } + /* Update checksum */ + if (r == ARCHIVE_OK && *size) { + zip->entry_crc32 = + crc32(zip->entry_crc32, *buff, *size); + } return (r); } diff --git a/lib/libarchive/test/test_read_format_zip.c b/lib/libarchive/test/test_read_format_zip.c index 8493ca55dcf3..d385b1cc6a2b 100644 --- a/lib/libarchive/test/test_read_format_zip.c +++ b/lib/libarchive/test/test_read_format_zip.c @@ -51,17 +51,20 @@ DEFINE_TEST(test_read_format_zip) assertEqualString("file1", archive_entry_pathname(ae)); assertEqualInt(1179604289, archive_entry_mtime(ae)); assertEqualInt(18, archive_entry_size(ae)); - assertEqualInt(18, archive_read_data(a, buff, 18)); + failure("archive_read_data() returns number of bytes read"); + assertEqualInt(18, archive_read_data(a, buff, 19)); assert(0 == memcmp(buff, "hello\nhello\nhello\n", 18)); assertA(0 == archive_read_next_header(a, &ae)); assertEqualString("file2", archive_entry_pathname(ae)); assertEqualInt(1179605932, archive_entry_mtime(ae)); assertEqualInt(18, archive_entry_size(ae)); - assertEqualInt(18, archive_read_data(a, buff, 18)); + failure("file2 has a bad CRC, so reading to end should fail"); + assertEqualInt(ARCHIVE_WARN, archive_read_data(a, buff, 19)); assert(0 == memcmp(buff, "hello\nhello\nhello\n", 18)); assertA(archive_compression(a) == ARCHIVE_COMPRESSION_NONE); assertA(archive_format(a) == ARCHIVE_FORMAT_ZIP); assert(0 == archive_read_close(a)); + #if ARCHIVE_API_VERSION > 1 assert(0 == archive_read_finish(a)); #else diff --git a/lib/libarchive/test/test_read_format_zip.zip.uu b/lib/libarchive/test/test_read_format_zip.zip.uu index f61340e2f930..fafbd8d38796 100644 --- a/lib/libarchive/test/test_read_format_zip.zip.uu +++ b/lib/libarchive/test/test_read_format_zip.zip.uu @@ -1,13 +1,13 @@ $FreeBSD$ -begin 645 test_read_format_zip.zip +begin 644 test_read_format_zip.zip M4$L#!`H``````%EFLS8````````````````$`!4`9&ER+U54"0`#&55/1AE5 M3T95>`0`Z`/H`U!+`P04````"`!O9K,V.C=F/0H````2````!0`5`&9I;&4Q M550)``-!54]&K%M/1E5X!`#H`^@#RTC-R<GGRD`B`5!+`P04````"`!::K,V -M.C=F/0H````2````!0`5`&9I;&4R550)``.L6T]&K%M/1E5X!`#H`^@#RTC- +M>%8T$@H````2````!0`5`&9I;&4R550)``.L6T]&K%M/1E5X!`#H`^@#RTC- MR<GGRD`B`5!+`0(7`PH``````%EFLS8````````````````$``T````````` M$`#M00````!D:7(O550%``,954]&57@``%!+`0(7`Q0````(`&]FLS8Z-V8] M"@```!(````%``T```````$```"D@3<```!F:6QE,554!0`#055/1E5X``!0 -M2P$"%P,4````"`!::K,V.C=F/0H````2````!0`-```````!````I(%Y```` +M2P$"%P,4````"`!::K,V>%8T$@H````2````!0`-```````!````I(%Y```` H9FEL93)55`4``ZQ;3T95>```4$L%!@`````#``,`OP```+L````````` ` end |
