Skip to content

Commit

Permalink
Merge pull request #3674 from facebook/zeroSeq_noExtra
Browse files Browse the repository at this point in the history
detect extraneous bytes in the Sequences section
  • Loading branch information
Cyan4973 authored Jun 13, 2023
2 parents c8888d9 + b462362 commit bd00ec6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/decompress/zstd_decompress_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/cli-tests/decompression/detectErrors.sh
Original file line number Diff line number Diff line change
@@ -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

5 changes: 5 additions & 0 deletions tests/playTests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit bd00ec6

Please sign in to comment.