erofs-utils: lib: fix compressed packed inodes
PATCH 1/1 erofs-utils: lib: fix compressed packed inodes
Commit b9b6493 fixed uncompressed packed inodes by not always writing compressed data, but it broke compressed packed inodes because now uncompressed file data is always written after the compressed data.
The new error handling always rewinds with lseek and falls through to write_uncompressed_file_from_fd, regardless of whether the compressed data was written successfully (ret = 0) or not (ret = -ENOSPC). This can result in corrupted files.
Fix it by simplifying the error handling to better match the old code.
--- lib/inode.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
lib/inode.c +8 -6
@@ -1927,14 +1927,16 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,DBG_BUGON (!ictx); ret =erofs_write_compressed_file (ictx); -if (ret && ret != -ENOSPC ) -return ERR_PTR (ret); +if (ret == -ENOSPC ) { + ret =lseek (fd,0 ,SEEK_SET ); +if (ret <0 ) +return ERR_PTR (-errno); - ret =lseek (fd,0 ,SEEK_SET ); -if (ret <0 ) -return ERR_PTR (-errno); + ret =write_uncompressed_file_from_fd (inode, fd); + } + }else { + ret =write_uncompressed_file_from_fd (inode, fd); } - ret =write_uncompressed_file_from_fd (inode, fd);if (ret)return ERR_PTR (ret);erofs_prepare_inode_buffer (inode);
Signature · 1 line
2.46.0
Gentle bump — let me know if anything needs to be changed!
Thanks,
Danny
Quoted 48 lines · Danny Lin
Commit b9b6493 fixed uncompressed packed inodes by not always writing compressed data, but it broke compressed packed inodes because now uncompressed file data is always written after the compressed data.
The new error handling always rewinds with lseek and falls through to
write_uncompressed_file_from_fd, regardless of whether the compressed data was written successfully (ret = 0) or not (ret =-ENOSPC). This can result in corrupted files.Fix it by simplifying the error handling to better match the old code.
Fixes b9b6493 ("erofs-utils: lib: fix uncompressed packed inode")Signed-off-by Danny Lin <[email protected]>--- lib/inode.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)lib/inode.c +8
-7@@ -1927,14 +1927,16 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,DBG_BUGON (!ictx); ret =erofs_write_compressed_file (ictx); -if (ret && ret != -ENOSPC ) -return ERR_PTR (ret); +if (ret == -ENOSPC ) { + ret =lseek (fd,0 ,SEEK_SET ); +if (ret <0 ) +return ERR_PTR (-errno); - ret =lseek (fd,0 ,SEEK_SET ); -if (ret <0 ) -return ERR_PTR (-errno); + ret =write_uncompressed_file_from_fd (inode, fd); + } + }else { + ret =write_uncompressed_file_from_fd (inode, fd); } - ret =write_uncompressed_file_from_fd (inode, fd);if (ret)return ERR_PTR (ret);erofs_prepare_inode_buffer (inode); --2.46.0
Hi Danny,
Thanks for the patch!
Sorry I somewhat missed the previous email..
Quoted 1 line · Danny Lin
Gentle bump — let me know if anything needs to be changed!
Does the following change resolve the issue too?
Also I think it
@@ -1927,7 +1926,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,
DBG_BUGON(!ictx);
ret = erofs_write_compressed_file(ictx);
- if (ret && ret != -ENOSPC)
+ if (ret != -ENOSPC)
return ERR_PTR(ret);
ret = lseek(fd, 0, SEEK_SET);Thanks,
Gao Xiang
Quoted 3 lines
Thanks,
Danny
Hi Danny,
Quoted 14 lines · Gao Xiang
Hi Danny,
Thanks for the patch!
Sorry I somewhat missed the previous email..Quoted 1 line · Danny Lin
Gentle bump — let me know if anything needs to be changed!
Does the following change resolve the issue too?
Also I think it
Fixes 2fdbd28ad4a3 ("erofs-utils: lib: fix uncompressed packed inode")
lib/inode.c struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi, · line 1932
Quoted 8 lines
lib/inode.c +1
-1@@ -1927,7 +1926,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi, DBG_BUGON(!ictx); ret = erofs_write_compressed_file(ictx); - if (ret && ret != -ENOSPC) + if (ret != -ENOSPC) return ERR_PTR(ret); ret = lseek(fd, 0, SEEK_SET);
Add some more words, I'm on releasing erofs-utils 1.8.2 this week.
So if the diff above also fixes the issue, could you submit a patch for this so I could merge in time?
Thanks,
Gsao Xiang
Quoted 7 lines
Thanks,
Gao XiangQuoted 3 lines
Thanks,
Danny
Quoted 13 lines · Gao Xiang
Hi Danny,
Quoted 9 lines · Gao Xiang
Hi Danny,
Thanks for the patch!
Sorry I somewhat missed the previous email..Quoted 1 line · Danny Lin
Gentle bump — let me know if anything needs to be changed!
Does the following change resolve the issue too?
Thanks for the suggestion. I tried your patch and it segfaults instead.
From a quick glance at the surrounding code, it doesn't seem correct because the calls to erofs_prepare_inode_buffer and erofs_write_tail_end are skipped if ret == 0.
Quoted 3 lines
Quoted 3 lines
Also I think it
Fixes 2fdbd28ad4a3 ("erofs-utils: lib: fix uncompressed packed inode")
Ah, nice catch. Do you want me to resubmit or will you fix it when applying the patch?
Quoted 14 lines
lib/inode.c struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi, · line 1932
Quoted 10 lines
lib/inode.c +1
-1@@ -1927,7 +1926,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,DBG_BUGON (!ictx); ret =erofs_write_compressed_file (ictx); -if (ret && ret != -ENOSPC ) +if (ret != -ENOSPC )return ERR_PTR (ret); ret =lseek (fd,0 ,SEEK_SET );Add some more words, I'm on releasing erofs-utils 1.8.2 this week.
Quoted 14 lines
So if the diff above also fixes the issue, could you submit a patch for this so I could merge in time?
Thanks,
Gsao XiangQuoted 7 lines
Thanks,
Gao XiangQuoted 3 lines
Thanks,
Danny
Thanks,
Danny
Quoted 11 lines · Danny Lin
Quoted 9 lines · Gao Xiang
Hi Danny,
Quoted 5 lines · Gao Xiang
Hi Danny,
Thanks for the patch!
Sorry I somewhat missed the previous email..
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines · Danny Lin
Quoted 1 line
Gentle bump — let me know if anything needs to be changed!
Does the following change resolve the issue too?
Thanks for the suggestion. I tried your patch and it segfaults instead.
I think the segfault is because it returns ERR_PTR(0) instead of inode on success. That should be an easy fix but we'd still be skipping erofs_prepare_inode_buffer and erofs_write_tail_end.
Quoted 37 lines
From a quick glance at the surrounding code, it doesn't seem correct because the calls to
erofs_prepare_inode_bufferanderofs_write_tail_endare skipped if ret == 0.Quoted 3 lines
Quoted 3 lines
Also I think it
Fixes 2fdbd28ad4a3 ("erofs-utils: lib: fix uncompressed packed inode")Ah, nice catch. Do you want me to resubmit or will you fix it when applying the patch?
Quoted 25 lines
lib/inode.c struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi, · line 1932
Quoted 10 lines
lib/inode.c +1
-1@@ -1927,7 +1926,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,DBG_BUGON (!ictx); ret =erofs_write_compressed_file (ictx); -if (ret && ret != -ENOSPC ) +if (ret != -ENOSPC )return ERR_PTR (ret); ret =lseek (fd,0 ,SEEK_SET );Add some more words, I'm on releasing erofs-utils 1.8.2 this week.
So if the diff above also fixes the issue, could you submit a patch for this so I could merge in time?
Thanks,
Gsao XiangQuoted 5 lines
Thanks,
Gao XiangQuoted 1 line
Quoted 6 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Thanks,
DannyThanks,
Danny
Thanks,
Danny
Hi Danny,
Quoted 15 lines · Danny Lin
Quoted 14 lines · Danny Lin
Quoted 12 lines · Gao Xiang
Hi Danny,
Quoted 8 lines · Gao Xiang
Hi Danny,
Thanks for the patch!
Sorry I somewhat missed the previous email..Quoted 1 line · Danny Lin
Gentle bump — let me know if anything needs to be changed!
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Does the following change resolve the issue too?
Thanks for the suggestion. I tried your patch and it segfaults instead.
I think the segfault is because it returns
ERR_PTR(0)instead of inode on success. That should be an easy fix but we'd still be skippingerofs_prepare_inode_bufferanderofs_write_tail_end.
Yeah, correct, thanks for catching! so I think just?
@@ -1927,7 +1926,9 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,
DBG_BUGON(!ictx);
ret = erofs_write_compressed_file(ictx);- if (ret && ret != -ENOSPC)
+ if (!ret)
+ goto out;
+ if (ret != -ENOSPC)
return ERR_PTR(ret);
ret = lseek(fd, 0, SEEK_SET);
@@ -1937,6 +1938,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,
ret = write_uncompressed_file_from_fd(inode, fd);
if (ret)
return ERR_PTR(ret);
+out:
erofs_prepare_inode_buffer(inode);
erofs_write_tail_end(inode);
return inode;Quoted 7 lines
Quoted 7 lines
From a quick glance at the surrounding code, it doesn't seem correct
because the calls toerofs_prepare_inode_bufferanderofs_write_tail_endare skipped if ret == 0.Quoted 1 line
Quoted 1 line
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Also I think it
Fixes 2fdbd28ad4a3 ("erofs-utils: lib: fix uncompressed packed inode")Ah, nice catch. Do you want me to resubmit or will you fix it when applying the patch?
Could you please resubmit since you're credited on this?
Thanks,
Gao Xiang
PATCH v2 1/1 erofs-utils: lib: fix compressed packed inodes
In reply to Danny Lin via Linux-erofsFrom: Danny Lin <[email protected]>
Commit 2fdbd28 fixed uncompressed packed inodes by not always writing compressed data, but it broke compressed packed inodes because now uncompressed file data is always written after the compressed data.
The new error handling always rewinds with lseek and falls through to write_uncompressed_file_from_fd, regardless of whether the compressed data was written successfully (ret = 0) or not (ret = -ENOSPC). This can result in corrupted files.
Fix it by simplifying the error handling to better match the old code.
--- lib/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
lib/inode.c +4 -1
@@ -1927,7 +1927,9 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi,DBG_BUGON (!ictx); ret =erofs_write_compressed_file (ictx); -if (ret && ret != -ENOSPC ) +if (!ret) + goto out; +if (ret != -ENOSPC )return ERR_PTR (ret); ret =lseek (fd,0 ,SEEK_SET );
@@ -1937,6 +1939,7 @@ struct erofs_inode *erofs_mkfs_build_special_from_fd(struct erofs_sb_info *sbi, ret =write_uncompressed_file_from_fd (inode, fd);if (ret)return ERR_PTR (ret); +out:erofs_prepare_inode_buffer (inode);erofs_write_tail_end (inode);return inode;
Signature · 1 line
2.46.1
Quoted 11 lines · On 2024/9/23 13:17, [email protected] wrote:
From: Danny Lin <[email protected]>
Commit 2fdbd28 fixed uncompressed packed inodes by not always writing compressed data, but it broke compressed packed inodes because now uncompressed file data is always written after the compressed data.
The new error handling always rewinds with lseek and falls through to
write_uncompressed_file_from_fd, regardless of whether the compressed data was written successfully (ret = 0) or not (ret =-ENOSPC). This can result in corrupted files.
Quoted 5 lines
Fix it by simplifying the error handling to better match the old code.
Fixes 2fdbd28 ("erofs-utils: lib: fix uncompressed packed inode")Co-authored-by Gao Xiang <[email protected]>Signed-off-by Danny Lin <[email protected]>
Thanks,
Gao Xiang