[PATCH 2/2] erofs-utils: lib: handle duplicate dirents in incremental builds

Gao Xiang hsiangkao at linux.alibaba.com
Sun Sep 28 02:25:48 AEST 2025


Corrupted base images may contain duplicate dirents.

Fixes: f64d9d02576b ("erofs-utils: introduce incremental builds")
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/rebuild.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/rebuild.c b/lib/rebuild.c
index 64779cb..e3c7eb8 100644
--- a/lib/rebuild.c
+++ b/lib/rebuild.c
@@ -484,6 +484,11 @@ static int erofs_rebuild_basedir_dirent_iter(struct erofs_dir_context *ctx)
 		d->validnid = true;
 		if (!mergedir->whiteouts && erofs_dentry_is_wht(dir->sbi, d))
 			mergedir->whiteouts = true;
+	} else if (__erofs_unlikely(d->validnid)) {
+		/* The base image appears to be corrupted */
+		DBG_BUGON(1);
+		ret = -EFSCORRUPTED;
+		goto out;
 	} else {
 		struct erofs_inode *inode = d->inode;
 
-- 
2.43.5



More information about the Linux-erofs mailing list