[PATCH v2] erofs-utils: tar: handle gzread errors
Gao Xiang
hsiangkao at linux.alibaba.com
Tue Mar 31 18:51:14 AEDT 2026
From: Vansh Choudhary <ch at vnsh.in>
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>
Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
v2:
- some cleanups.
I will apply this one.
lib/tar.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/tar.c b/lib/tar.c
index eca29f54c06f..0fe9853dfb16 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -170,16 +170,17 @@ 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) {
- int errnum;
+ if (ret <= 0) {
const char *errstr;
+ int errnum;
errstr = gzerror(ios->handler, &errnum);
- if (errnum != Z_STREAM_END) {
+ if (!ret && errnum == Z_STREAM_END) {
+ ios->feof = true;
+ } else {
erofs_err("failed to gzread: %s", errstr);
return -EIO;
}
- ios->feof = true;
}
ios->tail += ret;
#else
--
2.43.5
More information about the Linux-erofs
mailing list