[PATCH] lib/decompress: track total bytes consumed with fill function

From: Josh Law

Date: Sun Apr 19 2026 - 08:34:36 EST


When using a fill function to read chunks, pos was only tracking the
offset within the current buffer. It completely ignored all previously
read chunks.

Track the consumed bytes across chunks so we report the actual total
back to the caller.

Signed-off-by: Josh Law <joshlaw48@xxxxxxxxx>
---
lib/decompress_inflate.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c
index e19199f4a684..f595fd4bb5b3 100644
--- a/lib/decompress_inflate.c
+++ b/lib/decompress_inflate.c
@@ -48,6 +48,7 @@ static int INIT __gunzip(unsigned char *buf, long len,
u8 *zbuf;
struct z_stream_s *strm;
int rc;
+ size_t rcved = 0;

rc = -1;
if (flush) {
@@ -143,7 +144,7 @@ static int INIT __gunzip(unsigned char *buf, long len,

while (rc == Z_OK) {
if (strm->avail_in == 0) {
- /* TODO: handle case where both pos and fill are set */
+ rcved += strm->next_in - zbuf;
len = fill(zbuf, GZIP_IOBUF_SIZE);
if (len < 0) {
rc = -1;
@@ -180,7 +181,7 @@ static int INIT __gunzip(unsigned char *buf, long len,
zlib_inflateEnd(strm);
if (pos)
/* add + 8 to skip over trailer */
- *pos = strm->next_in - zbuf+8;
+ *pos = rcved + (strm->next_in - zbuf) + 8;

gunzip_5:
free(strm->workspace);
--
2.43.0