erofs-utils: fsck: fix directory loop tracking
PATCH 1/1 erofs-utils: fsck: fix directory loop tracking
Store the current directory nid in the recursion stack.
The loop check compares inode.nid against the entries already on the stack, so pushing pnid there can miss self-referential directory loops and report the wrong failure later.
--- fsck/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fsck/main.c +1 -1
@@ -1022,7 +1022,7 @@ static int erofsfsck_check_inode(erofs_nid_t pnid, erofs_nid_t nid)for (i =0 ; i < fsckcfg.dirstack.top; ++i)if (inode.nid == fsckcfg.dirstack.dirs[i])return -ELOOP ; - fsckcfg.dirstack.dirs[fsckcfg.dirstack.top++] = pnid; + fsckcfg.dirstack.dirs[fsckcfg.dirstack.top++] = inode.nid; ret =erofs_iterate_dir (&ctx, true); --fsckcfg.dirstack.top; }
Signature · 1 line
2.51.0
Hi Xiang,
This patch LGTM.
I tested the fix by compiling fsck with a debug trace and running it against an image with a nested directory structure. I verified that the recursion stack now correctly pushes the current directory's NID (inode.nid) instead of inheriting the parent's NID, successfully fixing the loop tracking logic.
Quoted 9 lines · Nithurshen
Hi Xiang,
This patch LGTM.
I tested the fix by compiling fsck with a debug trace and running it against an image with a nested directory structure. I verified that the recursion stack now correctly pushes the current directory's NID (inode.nid) instead of inheriting the parent's NID, successfully fixing the loop tracking logic.
Please help work on a testcase too, thanks.
Quoted 3 lines
Reviewed-by Nithurshen <[email protected]>Tested-by Nithurshen <[email protected]>