Skip to contentSkip to conversation

erofs-utils: lib: fix erofs_pack_file_from_fd()

PATCH New Gao Xiang 1 participant 1 message Jun 17, 2025 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs-utils: lib: fix erofs_pack_file_from_fd()

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")
---
 lib/fragments.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/fragments.c +4 -1
index d63995e..e65963b 100644
@@ -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
Signature · 1 line
2.43.5