From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: linux-erofs@lists.ozlabs.org
Cc: Vansh Choudhary <ch@vnsh.in>, Gao Xiang <hsiangkao@linux.alibaba.com>
Subject: [PATCH v2] erofs-utils: tar: handle gzread errors
Date: Tue, 31 Mar 2026 15:51:14 +0800 [thread overview]
Message-ID: <20260331075114.1015683-1-hsiangkao@linux.alibaba.com> (raw)
In-Reply-To: <20260330180958.1372245-1-ch@vnsh.in>
From: Vansh Choudhary <ch@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@vnsh.in>
Signed-off-by: Gao Xiang <hsiangkao@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
prev parent reply other threads:[~2026-03-31 7:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-30 18:09 [PATCH] erofs-utils: tar: handle gzread errors Vansh Choudhary
2026-03-31 7:51 ` Gao Xiang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260331075114.1015683-1-hsiangkao@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=ch@vnsh.in \
--cc=linux-erofs@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox