From ee8a341ef45634a56596d7275a26c239eb1f854a Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Tue, 21 Oct 2008 05:08:35 +0000 Subject: If we don't know the file size, leave the file size unset. If it's not a regular file, don't return any data, even if the size is unknown. Update the Zip test with a hand-tweaked Zip archive that has a directory (with length-at-end set), a regular file without length-at-end set, and a regular file with length-at-end set and a bad CRC. Update the test code to verify that the file size is unset for the regular file with length-at-end. MFC after: 7 days --- lib/libarchive/archive_read_support_format_zip.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/libarchive/archive_read_support_format_zip.c') diff --git a/lib/libarchive/archive_read_support_format_zip.c b/lib/libarchive/archive_read_support_format_zip.c index e64c62c0c950..575cd331e4b9 100644 --- a/lib/libarchive/archive_read_support_format_zip.c +++ b/lib/libarchive/archive_read_support_format_zip.c @@ -444,7 +444,9 @@ zip_read_file_header(struct archive_read *a, struct archive_entry *entry, archive_entry_set_mtime(entry, zip->mtime, 0); archive_entry_set_ctime(entry, zip->ctime, 0); archive_entry_set_atime(entry, zip->atime, 0); - archive_entry_set_size(entry, zip->uncompressed_size); + /* Set the size only if it's meaningful. */ + if (0 == (zip->flags & ZIP_LENGTH_AT_END)) + archive_entry_set_size(entry, zip->uncompressed_size); zip->entry_bytes_remaining = zip->compressed_size; zip->entry_offset = 0; @@ -573,12 +575,16 @@ archive_read_format_zip_read_data(struct archive_read *a, } break; } + if (r != ARCHIVE_OK) + return (r); /* Update checksum */ - if (r == ARCHIVE_OK && *size) { + if (*size) zip->entry_crc32 = crc32(zip->entry_crc32, *buff, *size); - } - return (r); + /* Return EOF immediately if this is a non-regular file. */ + if (AE_IFREG != (zip->mode & AE_IFMT)) + return (ARCHIVE_EOF); + return (ARCHIVE_OK); } /* -- cgit v1.3