]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Issue 379: Zip containing another Zip is misparsed
authorTim Kientzle <kientzle@acm.org>
Sun, 4 Jan 2015 07:44:48 +0000 (23:44 -0800)
committerTim Kientzle <kientzle@acm.org>
Sun, 4 Jan 2015 07:44:48 +0000 (23:44 -0800)
Makefile.am
libarchive/test/CMakeLists.txt
libarchive/test/test_read_format_zip_nested.c [new file with mode: 0644]
libarchive/test/test_read_format_zip_nested.zip.uu [new file with mode: 0644]

index 9b9990f4bb9ad0c8b87d944e7db9b88e5cc1ab24..d355eefcffbe9952aa2c3fd873b587969d299825 100644 (file)
@@ -470,6 +470,7 @@ libarchive_test_SOURCES= \
        libarchive/test/test_read_format_zip_encryption_header.c \
        libarchive/test/test_read_format_zip_filename.c \
        libarchive/test/test_read_format_zip_mac_metadata.c \
+       libarchive/test/test_read_format_zip_nested.c \
        libarchive/test/test_read_format_zip_nofiletype.c \
        libarchive/test/test_read_format_zip_padded.c \
        libarchive/test/test_read_format_zip_sfx.c \
@@ -766,6 +767,7 @@ libarchive_test_EXTRA_DIST=\
        libarchive/test/test_read_format_zip_filename_utf8_ru2.zip.uu \
        libarchive/test/test_read_format_zip_length_at_end.zip.uu \
        libarchive/test/test_read_format_zip_mac_metadata.zip.uu \
+       libarchive/test/test_read_format_zip_nested.zip.uu \
        libarchive/test/test_read_format_zip_nofiletype.zip.uu \
        libarchive/test/test_read_format_zip_padded1.zip.uu \
        libarchive/test/test_read_format_zip_padded2.zip.uu \
index e97963df5261a4c8fcc5ea02caeb8bd0873169eb..e23a7c28a1e8962773ed83cbaa9fb768965f7ff9 100644 (file)
@@ -160,6 +160,7 @@ IF(ENABLE_TEST)
     test_read_format_zip_encryption_partially.c
     test_read_format_zip_filename.c
     test_read_format_zip_mac_metadata.c
+    test_read_format_zip_nested.c
     test_read_format_zip_nofiletype.c
     test_read_format_zip_padded.c
     test_read_format_zip_sfx.c
diff --git a/libarchive/test/test_read_format_zip_nested.c b/libarchive/test/test_read_format_zip_nested.c
new file mode 100644 (file)
index 0000000..000cafd
--- /dev/null
@@ -0,0 +1,85 @@
+/*-
+ * Copyright (c) 2003,2014 Tim Kientzle
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+DEFINE_TEST(test_read_format_zip_nested)
+{
+       const char *refname = "test_read_format_zip_nested.zip";
+       char *p, *inner;
+       size_t s, innerLength;
+       struct archive *a;
+       struct archive_entry *ae;
+
+       extract_reference_file(refname);
+       p = slurpfile(&s, refname);
+
+       /* Inspect outer Zip */
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
+       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, p, s, 1));
+
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualString("small.zip", archive_entry_pathname(ae));
+       assertEqualInt(211, archive_entry_size(ae));
+       assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
+       assertEqualInt(archive_entry_is_encrypted(ae), 0);
+       assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
+
+       /* Save contents of inner Zip. */
+       innerLength = archive_entry_size(ae);
+       inner = calloc(innerLength, 1);
+       assertEqualInt(innerLength, archive_read_data(a, inner, innerLength));
+
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualString("file.txt", archive_entry_pathname(ae));
+       assertEqualInt(53, archive_entry_size(ae));
+       assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
+       assertEqualInt(archive_entry_is_encrypted(ae), 0);
+       assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
+
+       /* Close outer Zip */
+       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
+
+       /* Inspect inner Zip. */
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip(a));
+       assertEqualIntA(a, ARCHIVE_OK, read_open_memory_seek(a, inner, innerLength, 1));
+       
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualString("another_file.txt", archive_entry_pathname(ae));
+       assertEqualInt(29, archive_entry_size(ae));
+       assertEqualInt(AE_IFREG, archive_entry_filetype(ae));
+       assertEqualInt(archive_entry_is_encrypted(ae), 0);
+       assertEqualIntA(a, archive_read_has_encrypted_entries(a), 0);
+
+       assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_free(a));
+
+       free(inner);
+}
diff --git a/libarchive/test/test_read_format_zip_nested.zip.uu b/libarchive/test/test_read_format_zip_nested.zip.uu
new file mode 100644 (file)
index 0000000..7b9e266
--- /dev/null
@@ -0,0 +1,16 @@
+begin 644 test_read_format_zip_nested.zip
+M4$L#!`H``````(U`.D6]]'5ITP```-,````)`!P`<VUA;&PN>FEP550)``-Y
+MGR14>9\D5'5X"P`!!..5`@`$@A8``%!+`P0*``````"+0#I%N2<3PAT````=
+M````$``<`&%N;W1H97)?9FEL92YT>'155`D``W:?)%1VGR14=7@+``$$XY4"
+M``2"%@``3VYL>2!T:&ES(&9I;&4@:7,@9&ES<&QA>65D+@I02P$"'@,*````
+M``"+0#I%N2<3PAT````=````$``8```````!````H($`````86YO=&AE<E]F
+M:6QE+G1X=%54!0`#=I\D5'5X"P`!!..5`@`$@A8``%!+!08``````0`!`%8`
+M``!G``````!02P,$"@``````F4`Z1?MM8Y,U````-0````@`'`!F:6QE+G1X
+M=%54"0`#DI\D5)*?)%1U>`L``03CE0(`!((6``!4:&4@>FEP(&%R8VAI=F4@
+M;65T861A=&$@:7,@;F]T(&1I<W!L87EE9"!C;W)R96-T;'DN"E!+`0(>`PH`
+M`````(U`.D6]]'5ITP```-,````)`!@```````````"@@0````!S;6%L;"YZ
+M:7!55`4``WF?)%1U>`L``03CE0(`!((6``!02P$"'@,*``````"90#I%^VUC
+MDS4````U````"``8```````!````H($6`0``9FEL92YT>'155`4``Y*?)%1U
+D>`L``03CE0(`!((6``!02P4&``````(``@"=````C0$`````
+`
+end