From 1ad25e99be9f23f77da9e1352095ce883c998023 Mon Sep 17 00:00:00 2001 From: Tim Kientzle Date: Sat, 3 Jan 2015 23:44:48 -0800 Subject: [PATCH] Issue 379: Zip containing another Zip is misparsed --- Makefile.am | 2 + libarchive/test/CMakeLists.txt | 1 + libarchive/test/test_read_format_zip_nested.c | 85 +++++++++++++++++++ .../test/test_read_format_zip_nested.zip.uu | 16 ++++ 4 files changed, 104 insertions(+) create mode 100644 libarchive/test/test_read_format_zip_nested.c create mode 100644 libarchive/test/test_read_format_zip_nested.zip.uu diff --git a/Makefile.am b/Makefile.am index 9b9990f4b..d355eefcf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index e97963df5..e23a7c28a 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -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 index 000000000..000cafd67 --- /dev/null +++ b/libarchive/test/test_read_format_zip_nested.c @@ -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 index 000000000..7b9e26632 --- /dev/null +++ b/libarchive/test/test_read_format_zip_nested.zip.uu @@ -0,0 +1,16 @@ +begin 644 test_read_format_zip_nested.zip +M4$L#!`H``````(U`.D6]]'5ITP```-,````)`!P`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`L``03CE0(`!((6``!4:&4@>FEP(&%R8VAI=F4@ +M;65T861A=&$@:7,@;F]T(&1I`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 -- 2.47.2