From 8b56d3f08d08d12df73de05f338edb84506247f2 Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Sun, 22 Sep 2024 22:17:29 -0700 Subject: [PATCH] erofs-utils: lib: fix compressed packed inodes 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. Fixes: 2fdbd28 ("erofs-utils: lib: fix uncompressed packed inode") Co-authored-by: Gao Xiang Signed-off-by: Danny Lin Reviewed-by: Gao Xiang Link: https://lore.kernel.org/r/20240923051759.7563-2-danny@orbstack.dev Signed-off-by: Gao Xiang --- lib/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/inode.c b/lib/inode.c index f08f395..7958d43 100644 --- a/lib/inode.c +++ b/lib/inode.c @@ -1926,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); @@ -1936,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; -- 2.34.1