mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josh Law <joshlaw48@gmail.com>
To: akpm@linux-foundation.org
Cc: linux-kernel@vger.kernel.org, Josh Law <joshlaw48@gmail.com>
Subject: [PATCH] lib/decompress: track total bytes consumed with fill function
Date: Sun, 19 Apr 2026 12:34:26 +0000	[thread overview]
Message-ID: <20260419123426.2084930-1-joshlaw48@gmail.com> (raw)

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@gmail.com>
---
 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


             reply	other threads:[~2026-04-19 12:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-19 12:34 Josh Law [this message]
2026-04-19 12:34 Josh Law

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=20260419123426.2084930-1-joshlaw48@gmail.com \
    --to=joshlaw48@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®