Linux-EROFS Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] erofs-utils: fsck: fix hole handling during extraction
@ 2026-09-17  3:53 Yifan Zhao
  2026-09-17  3:53 ` [PATCH 2/4] erofs-utils: mkfs: validate chunksize before computing chunkbits Yifan Zhao
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yifan Zhao @ 2026-09-17  3:53 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang, Yifan Zhao

Fix the following two issues in fsck.erofs --extract:

- Trailing holes leave extracted files too short.
- With --xattr-inode-digest, holes are hashed without advancing the
  output offset, so subsequent data is written at an earlier offset.

Assisted-by: Codex:gpt-6-astra
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
 fsck/main.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/fsck/main.c b/fsck/main.c
index b2d8f1a..55da9ea 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -569,7 +569,8 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd,
 						(const u8 *)zeros, chunk);
 					remain -= chunk;
 				}
-			} else if (outfd >= 0) {
+			}
+			if (outfd >= 0) {
 				ret = lseek(outfd, map.m_llen, SEEK_CUR);
 				if (ret < 0) {
 					ret = -errno;
@@ -855,6 +856,11 @@ again:
 	}
 
 	ret = erofsfsck_calc_inode_data(inode, fd);
+	if (!ret && ftruncate(fd, inode->i_size)) {
+		ret = -errno;
+		erofs_err("failed to set file size: %s (%s)",
+			  fsckcfg.extract_path, strerror(-ret));
+	}
 	close(fd);
 	return ret;
 }
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/4] erofs-utils: mkfs: validate chunksize before computing chunkbits
  2026-09-17  3:53 [PATCH 1/4] erofs-utils: fsck: fix hole handling during extraction Yifan Zhao
@ 2026-09-17  3:53 ` Yifan Zhao
  2026-09-17  3:53 ` [PATCH 3/4] erofs-utils: lib: fix rebuilding empty chunk-based files Yifan Zhao
  2026-09-17  3:53 ` [PATCH 4/4] erofs-utils: fsck: avoid truncating lseek() return values Yifan Zhao
  2 siblings, 0 replies; 4+ messages in thread
From: Yifan Zhao @ 2026-09-17  3:53 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang, Yifan Zhao

Assisted-by: Codex:gpt-6-astra
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
 mkfs/main.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mkfs/main.c b/mkfs/main.c
index d9b4e22..f0d3d8c 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -1262,8 +1262,9 @@ static int mkfs_parse_options_cfg(struct erofs_importer_params *params,
 		}
 
 		case 11:
+			errno = 0;
 			i = strtol(optarg, &endptr, 0);
-			if (*endptr != '\0') {
+			if (errno || *endptr != '\0' || i <= 0 || i > INT_MAX) {
 				erofs_err("invalid chunksize %s", optarg);
 				return -EINVAL;
 			}
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] erofs-utils: lib: fix rebuilding empty chunk-based files
  2026-09-17  3:53 [PATCH 1/4] erofs-utils: fsck: fix hole handling during extraction Yifan Zhao
  2026-09-17  3:53 ` [PATCH 2/4] erofs-utils: mkfs: validate chunksize before computing chunkbits Yifan Zhao
@ 2026-09-17  3:53 ` Yifan Zhao
  2026-09-17  3:53 ` [PATCH 4/4] erofs-utils: fsck: avoid truncating lseek() return values Yifan Zhao
  2 siblings, 0 replies; 4+ messages in thread
From: Yifan Zhao @ 2026-09-17  3:53 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang, Yifan Zhao

Switch empty files to FLAT_PLAIN before setting u.i_blkaddr to
EROFS_NULL_ADDR, which would otherwise overwrite u.chunkformat.

Fixes: b0b1711d4611 ("erofs-utils: support building image with reserved space")
Assisted-by: Codex:gpt-6-astra
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
 lib/rebuild.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/rebuild.c b/lib/rebuild.c
index ebac1c5..c378885 100644
--- a/lib/rebuild.c
+++ b/lib/rebuild.c
@@ -335,6 +335,7 @@ static int erofs_rebuild_update_inode(struct erofs_sb_info *dst_sb,
 	}
 	case S_IFREG:
 		if (!inode->i_size) {
+			inode->datalayout = EROFS_INODE_FLAT_PLAIN;
 			inode->u.i_blkaddr = EROFS_NULL_ADDR;
 			break;
 		}
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] erofs-utils: fsck: avoid truncating lseek() return values
  2026-09-17  3:53 [PATCH 1/4] erofs-utils: fsck: fix hole handling during extraction Yifan Zhao
  2026-09-17  3:53 ` [PATCH 2/4] erofs-utils: mkfs: validate chunksize before computing chunkbits Yifan Zhao
  2026-09-17  3:53 ` [PATCH 3/4] erofs-utils: lib: fix rebuilding empty chunk-based files Yifan Zhao
@ 2026-09-17  3:53 ` Yifan Zhao
  2 siblings, 0 replies; 4+ messages in thread
From: Yifan Zhao @ 2026-09-17  3:53 UTC (permalink / raw)
  To: linux-erofs; +Cc: xiang, Yifan Zhao

Check lseek() directly to avoid truncating its return value to int,
which can turn successful seeks beyond INT_MAX into extraction failures.

Fixes: b063ea316aa9 ("erofs-utils: fsck: extract chunk-based file with hole correctly")
Assisted-by: Codex:gpt-6-astra
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
 fsck/main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/fsck/main.c b/fsck/main.c
index 55da9ea..e54c523 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -571,8 +571,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd,
 				}
 			}
 			if (outfd >= 0) {
-				ret = lseek(outfd, map.m_llen, SEEK_CUR);
-				if (ret < 0) {
+				if (lseek(outfd, map.m_llen, SEEK_CUR) < 0) {
 					ret = -errno;
 					goto out;
 				}
-- 
2.55.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-09-17  3:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-17  3:53 [PATCH 1/4] erofs-utils: fsck: fix hole handling during extraction Yifan Zhao
2026-09-17  3:53 ` [PATCH 2/4] erofs-utils: mkfs: validate chunksize before computing chunkbits Yifan Zhao
2026-09-17  3:53 ` [PATCH 3/4] erofs-utils: lib: fix rebuilding empty chunk-based files Yifan Zhao
2026-09-17  3:53 ` [PATCH 4/4] erofs-utils: fsck: avoid truncating lseek() return values Yifan Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox