diff mbox series

[1/1] cmd: ximg: handle Z_BUF_ERROR explicitly in GZIP decompression

Message ID 20250508193724.4269-1-aristo.chen@canonical.com
State Accepted
Delegated to: Tom Rini
Headers show
Series [1/1] cmd: ximg: handle Z_BUF_ERROR explicitly in GZIP decompression | expand

Commit Message

Aristo Chen May 8, 2025, 7:37 p.m. UTC
When decompressing GZIP-compressed image parts via the `imxtract` command,
explicitly handle the `Z_BUF_ERROR` return value from `gunzip()` to provide
a clearer diagnostic. This error typically indicates that the destination
buffer is too small to hold the uncompressed data.

Signed-off-by: Aristo Chen <aristo.chen@canonical.com>
---
 cmd/ximg.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Casey Connolly May 22, 2025, 10:48 p.m. UTC | #1
On Thu, 08 May 2025 19:37:24 +0000, Aristo Chen wrote:

> When decompressing GZIP-compressed image parts via the `imxtract` command,
> explicitly handle the `Z_BUF_ERROR` return value from `gunzip()` to provide
> a clearer diagnostic. This error typically indicates that the destination
> buffer is too small to hold the uncompressed data.
> 
> 

Applied to u-boot/next, thanks!

[1/1] cmd: ximg: handle Z_BUF_ERROR explicitly in GZIP decompression
      commit: ef305ceff9c875a7c16fdffc5e120d8ddf6243b7
diff mbox series

Patch

diff --git a/cmd/ximg.c b/cmd/ximg.c
index 29d7c3279b3..0afa1bc6640 100644
--- a/cmd/ximg.c
+++ b/cmd/ximg.c
@@ -27,6 +27,7 @@ 
 #include <asm/byteorder.h>
 #include <asm/cache.h>
 #include <asm/io.h>
+#include <u-boot/zlib.h>
 
 static int
 do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
@@ -206,9 +207,13 @@  do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			break;
 #ifdef CONFIG_GZIP
 		case IH_COMP_GZIP:
+			int ret = 0;
 			printf("   Uncompressing part %d ... ", part);
-			if (gunzip((void *) dest, unc_len,
-				   (uchar *) data, &len) != 0) {
+			ret = gunzip((void *)dest, unc_len, (uchar *)data, &len);
+			if (ret == Z_BUF_ERROR) {
+				puts("Image too large: increase CONFIG_SYS_XIMG_LEN\n");
+				return 1;
+			} else if (ret != 0) {
 				puts("GUNZIP ERROR - image not loaded\n");
 				return 1;
 			}