mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] lib/decompress: track total bytes consumed with fill function
@ 2026-04-19 12:34 Josh Law
  0 siblings, 0 replies; 2+ messages in thread
From: Josh Law @ 2026-04-19 12:34 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Josh Law

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] lib/decompress: track total bytes consumed with fill function
@ 2026-04-19 12:34 Josh Law
  0 siblings, 0 replies; 2+ messages in thread
From: Josh Law @ 2026-04-19 12:34 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Josh Law

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-19 12:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-19 12:34 [PATCH] lib/decompress: track total bytes consumed with fill function Josh Law
  -- strict thread matches above, loose matches on Subject: below --
2026-04-19 12:34 Josh Law

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®