From: Tobias Stoeckmann Date: Wed, 8 Jul 2026 18:25:49 +0000 (+0200) Subject: cab: Add large LZX pre-tree test X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e04051cb4b0d6c03bd74d53bb5ef66a7fc72eef7;p=thirdparty%2Flibarchive.git cab: Add large LZX pre-tree test If a pre-tree is larger than 10 bit, libarchive fails to read the data. According to spec, up to 16 bit are valid. Example file provided by Duncan Horn. Thanks a lot! Signed-off-by: Tobias Stoeckmann --- diff --git a/Makefile.am b/Makefile.am index 98d4614d5..a8ba41cc1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -490,6 +490,7 @@ libarchive_test_SOURCES= \ libarchive/test/test_read_format_ar.c \ libarchive/test/test_read_format_cab.c \ libarchive/test/test_read_format_cab_filename.c \ + libarchive/test/test_read_format_cab_lzx_16bit.c \ libarchive/test/test_read_format_cab_lzx_e8.c \ libarchive/test/test_read_format_cab_lzx_oob.c \ libarchive/test/test_read_format_cab_mszip_oob.c \ @@ -918,6 +919,7 @@ libarchive_test_EXTRA_DIST=\ libarchive/test/test_read_format_cab_2.cab.uu \ libarchive/test/test_read_format_cab_3.cab.uu \ libarchive/test/test_read_format_cab_filename_cp932.cab.uu \ + libarchive/test/test_read_format_cab_lzx_16bit.cab.uu \ libarchive/test/test_read_format_cab_lzx_e8.cab.uu \ libarchive/test/test_read_format_cab_lzx_oob.cab.uu \ libarchive/test/test_read_format_cab_multi.p1.cab.uu \ diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index 97ea1123c..66c4a3e84 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -119,6 +119,7 @@ IF(ENABLE_TEST) test_read_format_ar.c test_read_format_cab.c test_read_format_cab_filename.c + test_read_format_cab_lzx_16bit.c test_read_format_cab_lzx_e8.c test_read_format_cab_lzx_oob.c test_read_format_cab_mszip_oob.c diff --git a/libarchive/test/test_read_format_cab_lzx_16bit.c b/libarchive/test/test_read_format_cab_lzx_16bit.c new file mode 100644 index 000000000..6efc3801f --- /dev/null +++ b/libarchive/test/test_read_format_cab_lzx_16bit.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c) 2026 Tobias Stoeckmann + * 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" + +DEFINE_TEST(test_read_format_cab_lzx_16bit) +{ + const char *refname = "test_read_format_cab_lzx_16bit.cab"; + struct archive *a; + struct archive_entry *ae; + char buff[16]; + + extract_reference_file(refname); + + assert((a = archive_read_new()) != NULL); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_cab(a)); + assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); + assertEqualIntA(a, ARCHIVE_OK, + archive_read_open_filename(a, refname, 10240)); + + /* Read entry. */ + assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); + assertEqualString(archive_entry_pathname(ae), "lzx16.bin"); + assertEqualInt(archive_entry_size(ae), 16); + assertEqualIntA(a, sizeof(buff), + archive_read_data(a, buff, sizeof(buff))); + assertEqualMem(buff, "ABABABABABABABAB", 16); + + assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a)); + assertEqualInt(ARCHIVE_OK, archive_read_free(a)); +} diff --git a/libarchive/test/test_read_format_cab_lzx_16bit.cab.uu b/libarchive/test/test_read_format_cab_lzx_16bit.cab.uu new file mode 100644 index 000000000..c1e6330a4 --- /dev/null +++ b/libarchive/test/test_read_format_cab_lzx_16bit.cab.uu @@ -0,0 +1,6 @@ +begin 644 test_read_format_cab_lzx_16bit.cab +M35-#1@````""`````````"P``````````P$!``$`````````1@````$``P\0 +M````````````(0```"``;'IX,38N8FEN```````T`!```!`#`6=%JXGOS0+P +H"R(%[??[`.@``````````'^(__\`X`````````(`_R'__ZK*`*@````` +` +end