Skip to contentSkip to conversation

erofs-utils: fsck: fix directory loop tracking

PATCH In review Vansh Choudhary 3 participants 3 messages Mar 21 – Mar 22

lore
Share & tools
lore
#0 lore raw

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
index 16a354f..3530707 100644
@@ -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
Reviewed-by Tested-by on v1 1/1
#1 lore raw

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.

#2 lore raw
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