[PATCH] erofs-utils: tests: add test for hardlink-to-root tar entries
Vansh Choudhary
ch at vnsh.in
Wed Apr 22 03:23:30 AEST 2026
This is a regression test for "erofs-utils: lib: check NULL from
erofs_rebuild_get_dentry()".
Signed-off-by: Vansh Choudhary <ch at vnsh.in>
---
tests/Makefile.am | 3 +++
tests/erofs/031 | 58 +++++++++++++++++++++++++++++++++++++++++++++
tests/erofs/031.out | 2 ++
3 files changed, 63 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 d8ac067..e7eacbe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -126,6 +126,9 @@ TESTS += erofs/028
# 029 - test FUSE daemon and kernel error handling on corrupted inodes
TESTS += erofs/029
+# 031 - regression test for NULL dentry on hardlink-to-root tar entry
+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..79f2a3e
--- /dev/null
+++ b/tests/erofs/031
@@ -0,0 +1,58 @@
+#!/bin/sh
+# SPDX-License-Identifier: MIT
+#
+# regression test for a NULL dentry crash in mkfs.erofs --tar when
+# a tar hardlink entry's linkname resolves to the root directory
+#
+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
+
+# two empty regular files; tar lays the second header at offset 512.
+: > $localdir/a
+: > $localdir/b
+(cd $localdir && tar --format=ustar -cf $tmp.tar a b) || \
+ _fail "failed to build input tar"
+
+# rewrite the second entry as a hardlink whose target is "."
+printf '1' | dd of=$tmp.tar bs=1 seek=668 count=1 conv=notrunc 2>/dev/null
+printf '.' | dd of=$tmp.tar bs=1 seek=669 count=1 conv=notrunc 2>/dev/null
+dd if=/dev/zero of=$tmp.tar bs=1 seek=670 count=99 conv=notrunc 2>/dev/null
+
+# recompute the ustar checksum (chksum field treated as 8 spaces)
+printf ' ' | dd of=$tmp.tar bs=1 seek=660 count=8 conv=notrunc 2>/dev/null
+sum=`dd if=$tmp.tar bs=512 skip=1 count=1 2>/dev/null | \
+ od -An -tu1 -v | awk '{for(i=1;i<=NF;i++)s+=$i}END{printf "%06o",s}'`
+printf '%s\000 ' "$sum" | dd of=$tmp.tar bs=1 seek=660 count=8 conv=notrunc 2>/dev/null
+
+$MKFS_EROFS_PROG --tar $SCRATCH_DEV $tmp.tar >> $seqres.full 2>&1
+rc=$?
+[ $rc -ge 128 ] && _fail "mkfs.erofs crashed on hardlink-to-root (rc=$rc)"
+[ $rc -eq 0 ] && _fail "mkfs.erofs unexpectedly accepted hardlink-to-root"
+
+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
More information about the Linux-erofs
mailing list