erofs-utils: tar: handle gzread errors
PATCH 1/1 erofs-utils: tar: handle gzread errors
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 <[email protected]>
--- lib/tar.c | 8 ++++++++ 1 file changed, 8 insertions(+)
lib/tar.c +8 -0
@@ -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;
Signature · 1 line
2.43.0
PATCH v2 1/1 erofs-utils: tar: handle gzread errors
From: Vansh Choudhary <[email protected]>
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 <[email protected]>
Signed-off-by Gao Xiang <[email protected]>
---
v2:
- some cleanups.
I will apply this one.
lib/tar.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
lib/tar.c +5 -4
@@ -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
Signature · 1 line
2.43.5