erofs-utils: fsck: fix hole handling during extraction
PATCH 1/4 erofs-utils: fsck: fix hole handling during extraction
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.
--- fsck/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fsck/main.c +7 -1
@@ -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; }
Signature · 1 line
2.55.0
PATCH 2/4 erofs-utils: mkfs: validate chunksize before computing chunkbits
--- mkfs/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
mkfs/main.c +2 -1
@@ -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 ; }
Signature · 1 line
2.55.0
PATCH 3/4 erofs-utils: lib: fix rebuilding empty chunk-based files
In reply to Yifan ZhaoSwitch empty files to FLAT_PLAIN before setting u.i_blkaddr to EROFS_NULL_ADDR, which would otherwise overwrite u.chunkformat.
--- lib/rebuild.c | 1 + 1 file changed, 1 insertion(+)
lib/rebuild.c +1 -0
@@ -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 ; }
Signature · 1 line
2.55.0
PATCH 4/4 erofs-utils: fsck: avoid truncating lseek() return values
In reply to Yifan ZhaoCheck lseek() directly to avoid truncating its return value to int, which can turn successful seeks beyond INT_MAX into extraction failures.
--- fsck/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fsck/main.c +1 -2
@@ -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; }
Signature · 1 line
2.55.0