Skip to contentSkip to conversation

erofs-utils: lib: handle short reads in inode fingerprint

PATCH New Vansh Choudhary 1 participant 1 message Apr 20 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs-utils: lib: handle short reads in inode fingerprint

Treat a zero-byte erofs_io_pread() return as I/O failure when hashing inode->i_size bytes for the inode fingerprint.

Without that, pread() returning 0 on EOF (source shorter than i_size, e.g. truncated between stat() and fingerprinting) leaves "remaining" unchanged and mkfs.erofs spins forever.

Fixes 5e7cdf7593ae ("erofs-utils: mkfs: add `--xattr-inode-digest` option")
---
 lib/inode.c | 2 ++
 1 file changed, 2 insertions(+)
lib/inode.c +2 -0
index b3e5f62..bac21dc 100644
@@ -2005,6 +2005,8 @@ static int erofs_set_inode_fingerprint(struct erofs_inode *inode, int fd,
 				     min_t(u64, remaining, sizeof(buf)), pos);
 		if (ret < 0)
 			return ret;
+		if (!ret)
+			return -EIO;
 		if (ret > 0)
 			erofs_sha256_process(&md, buf, ret);
 		remaining -= ret;
Signature · 1 line
2.43.0