From 58e523fedf48a304b54c4e42e46fd88d072f8751 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Thu, 19 Feb 2026 01:33:25 +0100 Subject: gunzip: Implement chunked decompression The current gzwrite() implementation is limited to 4 GiB compressed input buffer size due to struct z_stream_s { uInt avail_in } member, which is of type unsigned int. Current gzwrite() implementation sets the entire input buffer size as avail_in and performs decompression of the whole compressed input buffer in one round, which limits the size of input buffer to 4 GiB. Rework the decompression loop to use chunked approach, and decompress the input buffer in up to 4 GiB - 1 kiB avail_in chunks, possibly in multiple decompression rounds. This way, the compressed input buffer size is limited by gzwrite() function 'len' parameter type, which is unsigned long. In case of sandbox build, include parsing of 'gzwrite_chunk' environment variable, so the chunked approach can be thoroughly tested with non default chunk size. For non-sandbox builds, the chunk size is 4 GiB - 1 kiB. The gzwrite test case is extended to test various chunk sizes during gzwrite decompression test. Signed-off-by: Marek Vasut --- test/cmd/unzip.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'test/cmd') diff --git a/test/cmd/unzip.c b/test/cmd/unzip.c index b67c5ba1956..623a2785884 100644 --- a/test/cmd/unzip.c +++ b/test/cmd/unzip.c @@ -105,7 +105,7 @@ static int dm_test_cmd_zip_gzwrite(struct unit_test_state *uts) { struct udevice *dev; ofnode root, node; - int i, ret; + int i, j, ret; /* Enable the mmc9 node for this test */ root = oftree_root(oftree_default()); @@ -119,6 +119,16 @@ static int dm_test_cmd_zip_gzwrite(struct unit_test_state *uts) return ret; } + /* Test various sizes of decompression chunk sizes */ + for (j = 0; j < ARRAY_SIZE(sizes); j++) { + env_set_ulong("gzwrite_chunk", sizes[j]); + for (i = 0; i < ARRAY_SIZE(sizes); i++) { + ret = do_test_cmd_zip_unzip(uts, sizes[i], true); + if (ret) + return ret; + } + } + return 0; } DM_TEST(dm_test_cmd_zip_gzwrite, UTF_CONSOLE); -- cgit v1.2.3