[PATCH] erofs-utils: tests: add test for malformed PAX mtime parsing
Vansh Choudhary <[email protected]>
| Newsgroups | org.ozlabs.lists.linux-erofs |
|---|---|
| Message-ID | <[email protected]> |
This is a regression test for "erofs-utils: lib: tar: fix fractional PAX mtime parsing". Signed-off-by: Vansh Choudhary <[email protected]> --- tests/Makefile.am | 3 +++ tests/erofs/031 | 60 +++++++++++++++++++++++++++++++++++++++++++++ tests/erofs/031.out | 2 ++ 3 files changed, 65 insertions(+) create mode 100755 tests/erofs/031 create mode 100644 tests/erofs/031.out diff --git a/tests/Makefile.am b/tests/Makefile.am index cd1971a..36fbe92 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -129,6 +129,9 @@ TESTS += erofs/029 # 030 - regression test for NULL dentry on hardlink-to-root tar entry TESTS += erofs/030 +# 031 - regression test for malformed PAX mtime acceptance +TESTS += erofs/031 + # NEW TEST CASE HERE # TESTS += erofs/999 diff --git a/tests/erofs/031 b/tests/erofs/031 new file mode 100755 index 0000000..8644291 --- /dev/null +++ b/tests/erofs/031 @@ -0,0 +1,60 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +# +# Regression test for malformed PAX mtime acceptance in mkfs.erofs --tar +# +seq=`basename $0` +seqres=$RESULT_DIR/$(echo $0 | awk '{print $((NF-1))"/"$NF}' FS="/") + +# get standard environment, filters and checks +. "${srcdir}/common/rc" + +cleanup() +{ + cd / + rm -rf $tmp.* +} + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +echo "QA output created by $seq" + +if [ -z $SCRATCH_DEV ]; then + SCRATCH_DEV=$tmp/erofs_$seq.img + rm -f $SCRATCH_DEV +fi + +localdir="$tmp/$seq" +rm -rf $localdir +mkdir -p $localdir + +footar="$localdir/foo.tar" + +# build a PAX archive whose extended header carries a single record: +# "22 mtime=10.123456789\n" at payload offset 512. +: > $localdir/a +(cd $localdir && tar --format=pax \ + --pax-option='delete=atime,delete=ctime,mtime:=10.123456789' \ + -cf $footar a) || _fail "failed to build input tar" + +# verify the PAX payload before patching, so the test fails clearly if +# tar's output ever diverges from the expected layout. +hdr=`dd if=$footar bs=1 skip=512 count=22 2>/dev/null` +[ "$hdr" = "22 mtime=10.123456789" ] || \ + _fail "unexpected PAX payload: $hdr" + +# overwrite the trailing '9' (offset 532) with 'x' so the record reads +# "22 mtime=10.12345678x". sscanf("%d") would silently accept 12345678 +# and ignore the trailing 'x'; the fixed parser rejects it as -EIO. +printf 'x' | dd of=$footar bs=1 seek=532 count=1 conv=notrunc 2>/dev/null + +$MKFS_EROFS_PROG --tar $SCRATCH_DEV $footar >> $seqres.full 2>&1 +rc=$? +[ $rc -ge 128 ] && _fail "mkfs.erofs crashed on malformed PAX mtime (rc=$rc)" +[ $rc -eq 0 ] && _fail "mkfs.erofs unexpectedly accepted malformed PAX mtime" + +echo Silence is golden +status=0 +exit 0 diff --git a/tests/erofs/031.out b/tests/erofs/031.out new file mode 100644 index 0000000..b3d0bb0 --- /dev/null +++ b/tests/erofs/031.out @@ -0,0 +1,2 @@ +QA output created by 031 +Silence is golden -- 2.43.0