]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
zstd: Check for endless loop on 32 bit systems
authorTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 25 May 2026 18:59:44 +0000 (20:59 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Mon, 25 May 2026 20:11:12 +0000 (22:11 +0200)
It is possible to trigger an endless loop on 32 bit systems due to
a triggerable integer overflow.

Add a regression test for this.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Makefile.am
libarchive/test/CMakeLists.txt
libarchive/test/test_read_filter_zstd_raw.c [new file with mode: 0644]
libarchive/test/test_read_filter_zstd_raw_loop.uu [new file with mode: 0644]

index 2ea6c3ad66ee12012a184ddbabc5408be1b8a85e..ad3afe918929e055906ebd0d9e1b9a2ba5f6da2f 100644 (file)
@@ -476,6 +476,7 @@ libarchive_test_SOURCES= \
        libarchive/test/test_read_filter_lzop_multiple_parts.c \
        libarchive/test/test_read_filter_program.c \
        libarchive/test/test_read_filter_program_signature.c \
+       libarchive/test/test_read_filter_zstd_raw.c \
        libarchive/test/test_read_filter_uudecode.c \
        libarchive/test/test_read_filter_uudecode_raw.c \
        libarchive/test/test_read_format_7zip.c \
@@ -829,6 +830,7 @@ libarchive_test_EXTRA_DIST=\
        libarchive/test/test_read_filter_lzop_multiple_parts.tar.lzo.uu \
        libarchive/test/test_read_filter_uudecode_raw.uu \
        libarchive/test/test_read_filter_uudecode_base64_raw.uu \
+       libarchive/test/test_read_filter_zstd_raw_loop.uu \
        libarchive/test/test_read_format_mtree_crash747.mtree.bz2.uu \
        libarchive/test/test_read_format_mtree_noprint.mtree.uu \
        libarchive/test/test_read_format_7zip_bcj2_bzip2.7z.uu \
index 4f81d8800e22cb2e6456a41f6bf68569a2ed922d..866c84c762a466a9a621a6390e2d93bdff5be074 100644 (file)
@@ -110,6 +110,7 @@ IF(ENABLE_TEST)
     test_read_filter_program_signature.c
     test_read_filter_uudecode.c
     test_read_filter_uudecode_raw.c
+    test_read_filter_zstd_raw.c
     test_read_format_7zip.c
     test_read_format_7zip_encryption_data.c
     test_read_format_7zip_encryption_header.c
diff --git a/libarchive/test/test_read_filter_zstd_raw.c b/libarchive/test/test_read_filter_zstd_raw.c
new file mode 100644 (file)
index 0000000..5a4ea91
--- /dev/null
@@ -0,0 +1,46 @@
+/*-
+ * 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_filter_zstd_raw_loop)
+{
+       struct archive *a;
+
+       const char *name = "test_read_filter_zstd_raw_loop";
+
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_raw(a));
+       extract_reference_file(name);
+       assertEqualIntA(a, ARCHIVE_OK,
+           archive_read_open_filename(a, name, 200));
+
+       /* Verify that the filter detection did NOT work. */
+       assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_NONE);
+       assertEqualString(archive_filter_name(a, 0), "none");
+
+       assertEqualInt(ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
diff --git a/libarchive/test/test_read_filter_zstd_raw_loop.uu b/libarchive/test/test_read_filter_zstd_raw_loop.uu
new file mode 100644 (file)
index 0000000..9327156
--- /dev/null
@@ -0,0 +1,4 @@
+begin 644 test_read_filter_zstd_raw_loop
+,4"I-&/C___\HM2_]
+`
+end