]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
cab: Add large LZX pre-tree test
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 8 Jul 2026 18:25:49 +0000 (20:25 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Thu, 9 Jul 2026 06:37:34 +0000 (08:37 +0200)
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 <tobias@stoeckmann.org>
Makefile.am
libarchive/test/CMakeLists.txt
libarchive/test/test_read_format_cab_lzx_16bit.c [new file with mode: 0644]
libarchive/test/test_read_format_cab_lzx_16bit.cab.uu [new file with mode: 0644]

index 98d4614d59ac778479106f542e161f8e4f253ccd..a8ba41cc13a4b765e893116e107e25366b988369 100644 (file)
@@ -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 \
index 97ea1123cf486c7f968898df898cfff01740810d..66c4a3e8475633a0211fbbe21523008d3a140834 100644 (file)
@@ -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 (file)
index 0000000..6efc380
--- /dev/null
@@ -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 (file)
index 0000000..c1e6330
--- /dev/null
@@ -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