[PATCH] cpio_utils: print human zstd error

136 views
Skip to first unread message

Dominique Martinet

unread,
Apr 30, 2021, 5:01:01 AM4/30/21
to swup...@googlegroups.com, Dominique Martinet
ZSTD errors are negative numbers, printing these as %zu is
hard to read.
Use ZSTD_getErrorName() to get an easier error

Signed-off-by: Dominique Martinet <dominique...@atmark-techno.com>
---
(I stumbled on this because I had regenerated an encryption key
but not sent it to device, so decompression failed -- quite annoying
that we can't detect the aes key was wrong until decrpytion is finalized
but I don't see any way around it... Anyway, it won't hurt to have
readable errors, "Unknown frame descriptor" is slightly better than
"returned 18446744073709551606")

core/cpio_utils.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/cpio_utils.c b/core/cpio_utils.c
index b4131edc9525..67cc8055cac3 100644
--- a/core/cpio_utils.c
+++ b/core/cpio_utils.c
@@ -364,7 +364,8 @@ static int zstd_step(void* state, void* buffer, size_t size)
decompress_ret = ZSTD_decompressStream(s->dctx, &output, &s->input_view);

if (ZSTD_isError(decompress_ret)) {
- ERROR("ZSTD_decompressStream failed (returned %zu)", decompress_ret);
+ ERROR("ZSTD_decompressStream failed: %s",
+ ZSTD_getErrorName(decompress_ret));
return -1;
}

--
2.30.2

Stefano Babic

unread,
Apr 30, 2021, 5:12:36 AM4/30/21
to Dominique Martinet, swup...@googlegroups.com
Hi Dominique,

On 30.04.21 11:00, Dominique Martinet wrote:
> ZSTD errors are negative numbers, printing these as %zu is
> hard to read.
> Use ZSTD_getErrorName() to get an easier error
>
> Signed-off-by: Dominique Martinet <dominique...@atmark-techno.com>
> ---
> (I stumbled on this because I had regenerated an encryption key
> but not sent it to device, so decompression failed -- quite annoying
> that we can't detect the aes key was wrong until decrpytion is finalized
> but I don't see any way around it...

Right, I had also such a cases, and it becomes harder if sw-description
is encrypted, too. Anyway, the behavior is correct and SWUpdate cannot
distinguish between wrong key / corrupted file.

> Anyway, it won't hurt to have
> readable errors, "Unknown frame descriptor" is slightly better than
> "returned 18446744073709551606")

Of course.

>
> core/cpio_utils.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/core/cpio_utils.c b/core/cpio_utils.c
> index b4131edc9525..67cc8055cac3 100644
> --- a/core/cpio_utils.c
> +++ b/core/cpio_utils.c
> @@ -364,7 +364,8 @@ static int zstd_step(void* state, void* buffer, size_t size)
> decompress_ret = ZSTD_decompressStream(s->dctx, &output, &s->input_view);
>
> if (ZSTD_isError(decompress_ret)) {
> - ERROR("ZSTD_decompressStream failed (returned %zu)", decompress_ret);
> + ERROR("ZSTD_decompressStream failed: %s",
> + ZSTD_getErrorName(decompress_ret));
> return -1;
> }
>
>

I push it for the release, thanks !

Best regards,
Stefano Babic

--
=====================================================================
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sba...@denx.de
=====================================================================
Reply all
Reply to author
Forward
0 new messages