[PATCH] erofs-utils: tar: handle gzread errors

Vansh Choudhary ch at vnsh.in
Tue Mar 31 05:09:58 AEDT 2026


Treat gzread() errors as I/O failures before updating the stream
buffer state.

Without that, a negative gzread() result could underflow ios->tail
and leave the reader in a corrupted state.

Signed-off-by: Vansh Choudhary <ch at vnsh.in>
---
 lib/tar.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/lib/tar.c b/lib/tar.c
index 39e2321..871779a 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -174,6 +174,14 @@ int erofs_iostream_read(struct erofs_iostream *ios, void **buf, u64 bytes)
 #if defined(HAVE_ZLIB)
 			ret = gzread(ios->handler, ios->buffer + rabytes,
 				     ios->bufsize - rabytes);
+			if (ret < 0) {
+				int errnum;
+				const char *errstr;
+
+				errstr = gzerror(ios->handler, &errnum);
+				erofs_err("failed to gzread: %s", errstr);
+				return -EIO;
+			}
 			if (!ret) {
 				int errnum;
 				const char *errstr;
-- 
2.43.0



More information about the Linux-erofs mailing list