From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 2/2] uncompress: fix prebuffering
Date: Thu, 22 May 2025 20:59:05 +0200 [thread overview]
Message-ID: <20250522-uncompress-fixes-v1-2-18e796fa5e45@pengutronix.de> (raw)
In-Reply-To: <20250522-uncompress-fixes-v1-0-18e796fa5e45@pengutronix.de>
When uncompressing from a fill function we prebuffer the first 32 bytes
in order to detect the filetype. This prebuffer is then fed back into
the input stream in uncompress_fill().
This currently fails when uncompress_fill() crosses the prebuffered
size and continues reading from the original fill function. Advance
the buffer in this case to append the data to the buffer instead of
overwriting the data we already copied from the prebuffer.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
lib/uncompress.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/uncompress.c b/lib/uncompress.c
index c284bcc6ba5649419a226af14a78f42142cf5e74..6a4e5a34df8a69d22ae51b9fb7423f7a052ef480 100644
--- a/lib/uncompress.c
+++ b/lib/uncompress.c
@@ -45,6 +45,7 @@ static long uncompress_fill(void *buf, unsigned long len)
int now = min(len, uncompress_size);
memcpy(buf, uncompress_buf, now);
+ uncompress_buf += now;
uncompress_size -= now;
len -= now;
total = now;
@@ -77,17 +78,17 @@ int uncompress(unsigned char *inbuf, long len,
void(*error)(char *x));
int ret;
char *err;
+ void *uncompress_buf_free = NULL;
if (inbuf) {
ft = file_detect_compression_type(inbuf, len);
- uncompress_buf = NULL;
uncompress_size = 0;
} else {
if (!fill)
return -EINVAL;
uncompress_fill_fn = fill;
- uncompress_buf = xzalloc(32);
+ uncompress_buf_free = uncompress_buf = xzalloc(32);
uncompress_size = 32;
ret = fill(uncompress_buf, 32);
@@ -142,7 +143,7 @@ int uncompress(unsigned char *inbuf, long len,
ret = compfn(inbuf, len, fill ? uncompress_fill : NULL,
flush, output, pos, error_fn);
err:
- free(uncompress_buf);
+ free(uncompress_buf_free);
return ret;
}
--
2.39.5
next prev parent reply other threads:[~2025-05-22 19:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 18:59 [PATCH 0/2] uncompress: lz4 fixes Sascha Hauer
2025-05-22 18:59 ` [PATCH 1/2] initrd: fix lz4 decompress with initrd Sascha Hauer
2025-05-22 18:59 ` Sascha Hauer [this message]
2025-05-26 13:48 ` [PATCH 0/2] uncompress: lz4 fixes Sascha Hauer
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=20250522-uncompress-fixes-v1-2-18e796fa5e45@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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