[PATCH] erofs-utils: lib: fix erofs_pack_file_from_fd()
Gao Xiang
hsiangkao at linux.alibaba.com
Wed Jun 18 03:56:34 AEST 2025
If sendfile() fails, it should fall back to a plain copy.
Coverity-id: 554788
Fixes: 84bae6acdbee ("erofs-utils: lib: keep full data until the fragment is committed")
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
lib/fragments.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/lib/fragments.c b/lib/fragments.c
index d63995e..e65963b 100644
--- a/lib/fragments.c
+++ b/lib/fragments.c
@@ -242,6 +242,9 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofh)
char *memblock;
bool onheap = false;
+ if (__erofs_unlikely(!inode->i_size))
+ return 0;
+
offset = lseek(epi->fd, 0, SEEK_CUR);
if (offset < 0)
return -errno;
@@ -256,7 +259,7 @@ int erofs_pack_file_from_fd(struct erofs_inode *inode, int fd, u32 tofh)
sz = min_t(u64, remaining, UINT_MAX);
rc = sendfile(epi->fd, fd, NULL, sz);
if (rc < 0)
- goto out;
+ break;
remaining -= rc;
} while (remaining);
#endif
--
2.43.5
More information about the Linux-erofs
mailing list