]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
detect extraneous bytes in the Sequences section 3674/head
authorYann Collet <cyan@fb.com>
Tue, 13 Jun 2023 18:43:45 +0000 (11:43 -0700)
committerYann Collet <cyan@fb.com>
Tue, 13 Jun 2023 18:43:45 +0000 (11:43 -0700)
when nbSeq == 0.

Reported by @ip7z

lib/decompress/zstd_decompress_block.c
tests/cli-tests/decompression/detectErrors.sh [new file with mode: 0755]
tests/playTests.sh

index c63d06d6a9efea0329860f825a60ef56e220f101..93947ba584f362983b43d1f5f15d54b09f8d4c6b 100644 (file)
@@ -720,6 +720,8 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
 
     if (nbSeq == 0) {
         /* No sequence : section ends immediately */
+        RETURN_ERROR_IF(ip != iend, corruption_detected,
+            "extraneous data present in the Sequences section");
         return (size_t)(ip - istart);
     }
 
diff --git a/tests/cli-tests/decompression/detectErrors.sh b/tests/cli-tests/decompression/detectErrors.sh
new file mode 100755 (executable)
index 0000000..300cde3
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/sh
+
+set -e
+
+GOLDEN_DIR="$ZSTD_REPO_DIR/tests/golden-decompression-errors/"
+
+for file in "$GOLDEN_DIR"/*; do
+    zstd -t $file && die "should have detected an error"
+done
+exit 0
+
index f51776170bd64a28551eaf8b854661903c6964d5..05dc004299918514958e49399ae947484bb519d2 100755 (executable)
@@ -444,6 +444,11 @@ $DIFF -s tmp1 tmp
 touch tmp_empty
 zstd -d -o tmp2 "$TESTDIR/golden-decompression/empty-block.zst"
 $DIFF -s tmp2 tmp_empty
+
+zstd -t "$TESTDIR/golden-decompression/zeroSeq_2B.zst"
+
+zstd -t "$TESTDIR/golden-decompression-errors/zeroSeq_extraneous.zst" && die "invalid Sequences section should have been detected"
+
 rm -f tmp*
 
 println "\n===>  compress multiple files"