From owner-svn-src-head@FreeBSD.ORG Tue Oct 21 05:08:35 2008 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7E102106567C; Tue, 21 Oct 2008 05:08:35 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 6BA4A8FC1B; Tue, 21 Oct 2008 05:08:35 +0000 (UTC) (envelope-from kientzle@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id m9L58ZLg089723; Tue, 21 Oct 2008 05:08:35 GMT (envelope-from kientzle@svn.freebsd.org) Received: (from kientzle@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id m9L58Z4W089720; Tue, 21 Oct 2008 05:08:35 GMT (envelope-from kientzle@svn.freebsd.org) Message-Id: <200810210508.m9L58Z4W089720@svn.freebsd.org> From: Tim Kientzle Date: Tue, 21 Oct 2008 05:08:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r184109 - in head/lib/libarchive: . test X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Oct 2008 05:08:35 -0000 Author: kientzle Date: Tue Oct 21 05:08:35 2008 New Revision: 184109 URL: http://svn.freebsd.org/changeset/base/184109 Log: 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 Modified: head/lib/libarchive/archive_read_support_format_zip.c head/lib/libarchive/test/test_read_format_zip.c head/lib/libarchive/test/test_read_format_zip.zip.uu Modified: head/lib/libarchive/archive_read_support_format_zip.c ============================================================================== --- head/lib/libarchive/archive_read_support_format_zip.c Tue Oct 21 04:31:07 2008 (r184108) +++ head/lib/libarchive/archive_read_support_format_zip.c Tue Oct 21 05:08:35 2008 (r184109) @@ -444,7 +444,9 @@ zip_read_file_header(struct archive_read 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 } 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); } /* Modified: head/lib/libarchive/test/test_read_format_zip.c ============================================================================== --- head/lib/libarchive/test/test_read_format_zip.c Tue Oct 21 04:31:07 2008 (r184108) +++ head/lib/libarchive/test/test_read_format_zip.c Tue Oct 21 05:08:35 2008 (r184109) @@ -25,6 +25,12 @@ #include "test.h" __FBSDID("$FreeBSD$"); +/* + * The reference file for this has been manually tweaked so that: + * * file2 has length-at-end but file1 does not + * * file2 has an invalid CRC + */ + DEFINE_TEST(test_read_format_zip) { const char *refname = "test_read_format_zip.zip"; @@ -57,7 +63,8 @@ DEFINE_TEST(test_read_format_zip) 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)); + failure("file2 has length-at-end, so we shouldn't see a valid size"); + assertEqualInt(0, archive_entry_size_is_set(ae)); 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)); Modified: head/lib/libarchive/test/test_read_format_zip.zip.uu ============================================================================== --- head/lib/libarchive/test/test_read_format_zip.zip.uu Tue Oct 21 04:31:07 2008 (r184108) +++ head/lib/libarchive/test/test_read_format_zip.zip.uu Tue Oct 21 05:08:35 2008 (r184109) @@ -1,13 +1,14 @@ $FreeBSD$ 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%8T$@H````2````!0`5`&9I;&4R550)``.L6T]&K%M/1E5X!`#H`^@#RTC- -MR%8T$@H````2````!0`-```````!````I(%Y```` -H9FEL93)55`4``ZQ;3T95>```4$L%!@`````#``,`OP```+L````````` +M4$L#!`H`"````%EFLS8````````````````$`!4`9&ER+U54"0`#&55/1M19 +M_4A5>`0`Z`/H`U!+!P@```````````````!02P,$%`````@`;V:S-CHW9CT* +M````$@````4`%0!F:6QE,554"0`#055/1L!9_4A5>`0`Z`/H`\M(S`0`Z`/H`\M(S```4$L!`A<#%``(``@`;V:S-CHW9CT*````$@````4`#0`` +M`````0```.V!1P```&9I;&4Q550%``-!54]&57@``%!+`0(7`Q0`"``(`%IJ +MLS8Z-V8]"@```!(````%``T```````$```#M@8D```!F:6QE,E54!0`#K%M/ +;1E5X``!02P4&``````,``P"_````VP`````` ` end