]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Merge pull request #3093 from stoeckmann/lz4_skip
authorMartin Matuška <martin@matuska.de>
Mon, 1 Jun 2026 07:55:02 +0000 (09:55 +0200)
committerMartin Matuska <martin@matuska.de>
Tue, 23 Jun 2026 08:56:56 +0000 (10:56 +0200)
lz4: Improve truncated input stream detection
(cherry picked from commit 66026841b21540441ec5244316b24dce6549969f)

Makefile.am
libarchive/archive_read_support_filter_lz4.c
libarchive/test/CMakeLists.txt
libarchive/test/test_read_filter_lz4_raw.c [new file with mode: 0644]
libarchive/test/test_read_filter_lz4_raw_skip.uu [new file with mode: 0644]

index feee8b399a8f9b2265c0d0757a3681119a951c6a..eaf82fcd1ae671a34401d65ddb40abaed41e2b3b 100644 (file)
@@ -472,6 +472,7 @@ libarchive_test_SOURCES= \
        libarchive/test/test_read_filter_grzip.c \
        libarchive/test/test_read_filter_gzip_recursive.c \
        libarchive/test/test_read_filter_lrzip.c \
+       libarchive/test/test_read_filter_lz4_raw.c \
        libarchive/test/test_read_filter_lzop.c \
        libarchive/test/test_read_filter_lzop_multiple_parts.c \
        libarchive/test/test_read_filter_program.c \
@@ -826,6 +827,7 @@ libarchive_test_EXTRA_DIST=\
        libarchive/test/test_read_filter_grzip.tar.grz.uu \
        libarchive/test/test_read_filter_gzip_recursive.gz.uu \
        libarchive/test/test_read_filter_lrzip.tar.lrz.uu \
+       libarchive/test/test_read_filter_lz4_raw_skip.uu \
        libarchive/test/test_read_filter_lzop.tar.lzo.uu \
        libarchive/test/test_read_filter_lzop_multiple_parts.tar.lzo.uu \
        libarchive/test/test_read_filter_uudecode_raw.uu \
index cc59589f4dfeb94712094137d615dd54fc80d7f0..15f648102e790f2e753308af7b81fd6b8ed4a715 100644 (file)
@@ -407,9 +407,15 @@ lz4_filter_read(struct archive_read_filter *self, const void **p)
                                    "Malformed lz4 data");
                                return (ARCHIVE_FATAL);
                        }
-                       uint32_t skip_bytes = archive_le32dec(read_buf);
-                       __archive_read_filter_consume(self->upstream,
-                               4 + skip_bytes);
+                       int64_t skip_bytes = archive_le32dec(read_buf);
+                       if (__archive_read_filter_consume(self->upstream,
+                           4 + skip_bytes) < 0) {
+                               archive_set_error(
+                                   &self->archive->archive,
+                                   ARCHIVE_ERRNO_MISC,
+                                   "Malformed lz4 data");
+                               return (ARCHIVE_FATAL);
+                       }
                } else {
                        /* Ignore following unrecognized data. */
                        state->eof = 1;
index 6cd95ce00dfdee4136b12d81dcb369f3fc12b46b..c67e71f3d6a9ecc8b850a0ad4c65d4a0c433c1a5 100644 (file)
@@ -104,6 +104,7 @@ IF(ENABLE_TEST)
     test_read_filter_grzip.c
     test_read_filter_gzip_recursive.c
     test_read_filter_lrzip.c
+    test_read_filter_lz4_raw.c
     test_read_filter_lzop.c
     test_read_filter_lzop_multiple_parts.c
     test_read_filter_program.c
diff --git a/libarchive/test/test_read_filter_lz4_raw.c b/libarchive/test/test_read_filter_lz4_raw.c
new file mode 100644 (file)
index 0000000..9cbb561
--- /dev/null
@@ -0,0 +1,40 @@
+/*-
+ * 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_lz4_raw_skip)
+{
+       struct archive *a;
+
+       const char *name = "test_read_filter_lz4_raw_skip";
+
+       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_FATAL,
+           archive_read_open_filename(a, name, 200));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
diff --git a/libarchive/test/test_read_filter_lz4_raw_skip.uu b/libarchive/test/test_read_filter_lz4_raw_skip.uu
new file mode 100644 (file)
index 0000000..aaff306
--- /dev/null
@@ -0,0 +1,4 @@
+begin 644 test_read_filter_lz4_raw_skip.uu
+<!")-&&1`IP$``(`*`````%+3R8%0*DT8_/___P``
+`
+end