[PATCH] erofs-utils: lib: handle short reads in inode fingerprint

Vansh Choudhary <[email protected]>
Newsgroups org.ozlabs.lists.linux-erofs
Message-ID <[email protected]>
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")
Signed-off-by: Vansh Choudhary <[email protected]>
---
 lib/inode.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/inode.c b/lib/inode.c
index b3e5f62..bac21dc 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -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;
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.