1
0
mirror of https://github.com/lz4/lz4.git synced 2026-10-24 01:48:57 +03:00
Files
lz4/tests/test-lz4-skippable.sh
akashdeshmukh-git 26f121584a lz4io: detect truncated skippable frames in regular files
fseek() succeeds beyond end of file, so a skippable frame whose
declared size exceeds the remaining input was silently accepted
when reading from a file (`lz4 -t`, `lz4 -d` and `lz4 --list` all
reported success), while the same input from a pipe correctly failed
with "Error 43 : cannot skip skippable area".

fseek_u32() now seeks to the last byte of the area and reads it,
so truncation is detected the same way for files and pipes.
2026-10-20 08:32:54 +00:00

30 lines
686 B
Bash
Executable File

#!/bin/sh
SKIPFILE="goldenSamples/skip.bin"
FPREFIX="tmp-lsk"
set -e
remove () {
rm "$FPREFIX"*
}
trap remove EXIT
set -x
lz4 -dc $SKIPFILE
lz4 -dc < $SKIPFILE
printf "Hello from Valid Frame!\n" | lz4 -c > $FPREFIX.lz4
cat $SKIPFILE $FPREFIX.lz4 $SKIPFILE | lz4 -dc
# truncated skippable frame : must fail, whether input is a file or a pipe
head -c 20 $SKIPFILE > $FPREFIX-trunc.lz4
if lz4 -t $FPREFIX-trunc.lz4; then false; fi
if lz4 -t < $FPREFIX-trunc.lz4; then false; fi
if cat $FPREFIX-trunc.lz4 | lz4 -t; then false; fi
if lz4 --list $FPREFIX-trunc.lz4; then false; fi
# skippable frame ending exactly at end of file remains valid
lz4 -t $SKIPFILE
lz4 --list $SKIPFILE