* [U-Boot] [PATCH] Fix gunzip in case of insufficient output buffer
@ 2009-01-02 14:11 Matthias Fuchs
2009-01-19 12:21 ` Matthias Fuchs
2009-01-27 19:59 ` Wolfgang Denk
0 siblings, 2 replies; 3+ messages in thread
From: Matthias Fuchs @ 2009-01-02 14:11 UTC (permalink / raw)
To: u-boot
U-Boot's gunzip() function does not handle the return code
of zlib's inflate() function correctly. gunzip() is implemented
to uncompress all input data in one run. So the correct return
code for the good case is Z_STREAM_END. In case of insufficient
output buffer memory inflate returns Z_OK. For gunzip() this
is an error.
It also makes sense to me to call inflateEnd() also in case
of an error.
Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
---
common/cmd_bootm.c | 2 +-
lib_generic/gunzip.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
index a8f85e9..9055672 100644
--- a/common/cmd_bootm.c
+++ b/common/cmd_bootm.c
@@ -350,7 +350,7 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
printf (" Uncompressing %s ... ", type_name);
if (gunzip ((void *)load, unc_len,
(uchar *)image_start, &image_len) != 0) {
- puts ("GUNZIP: uncompress or overwrite error "
+ puts ("GUNZIP: uncompress, out-of-mem or overwrite error "
"- must RESET board to recover\n");
if (boot_progress)
show_boot_progress (-6);
diff --git a/lib_generic/gunzip.c b/lib_generic/gunzip.c
index 74f0bf9..5bcf5b7 100644
--- a/lib_generic/gunzip.c
+++ b/lib_generic/gunzip.c
@@ -102,8 +102,9 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
s.next_out = dst;
s.avail_out = dstlen;
r = inflate(&s, Z_FINISH);
- if (r != Z_OK && r != Z_STREAM_END) {
+ if (r != Z_STREAM_END) {
printf ("Error: inflate() returned %d\n", r);
+ inflateEnd(&s);
return (-1);
}
*lenp = s.next_out - (unsigned char *) dst;
--
1.5.6.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] Fix gunzip in case of insufficient output buffer
2009-01-02 14:11 [U-Boot] [PATCH] Fix gunzip in case of insufficient output buffer Matthias Fuchs
@ 2009-01-19 12:21 ` Matthias Fuchs
2009-01-27 19:59 ` Wolfgang Denk
1 sibling, 0 replies; 3+ messages in thread
From: Matthias Fuchs @ 2009-01-19 12:21 UTC (permalink / raw)
To: u-boot
Hi,
did anybody check my gunzip fix? I'm not a zlib expert,
but I think we have a little issue here.
Matthias
On Friday 02 January 2009 15:11, Matthias Fuchs wrote:
> U-Boot's gunzip() function does not handle the return code
> of zlib's inflate() function correctly. gunzip() is implemented
> to uncompress all input data in one run. So the correct return
> code for the good case is Z_STREAM_END. In case of insufficient
> output buffer memory inflate returns Z_OK. For gunzip() this
> is an error.
>
> It also makes sense to me to call inflateEnd() also in case
> of an error.
>
> Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
> ---
> common/cmd_bootm.c | 2 +-
> lib_generic/gunzip.c | 3 ++-
> 2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c
> index a8f85e9..9055672 100644
> --- a/common/cmd_bootm.c
> +++ b/common/cmd_bootm.c
> @@ -350,7 +350,7 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
> printf (" Uncompressing %s ... ", type_name);
> if (gunzip ((void *)load, unc_len,
> (uchar *)image_start, &image_len) != 0) {
> - puts ("GUNZIP: uncompress or overwrite error "
> + puts ("GUNZIP: uncompress, out-of-mem or overwrite error "
> "- must RESET board to recover\n");
> if (boot_progress)
> show_boot_progress (-6);
> diff --git a/lib_generic/gunzip.c b/lib_generic/gunzip.c
> index 74f0bf9..5bcf5b7 100644
> --- a/lib_generic/gunzip.c
> +++ b/lib_generic/gunzip.c
> @@ -102,8 +102,9 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
> s.next_out = dst;
> s.avail_out = dstlen;
> r = inflate(&s, Z_FINISH);
> - if (r != Z_OK && r != Z_STREAM_END) {
> + if (r != Z_STREAM_END) {
> printf ("Error: inflate() returned %d\n", r);
> + inflateEnd(&s);
> return (-1);
> }
> *lenp = s.next_out - (unsigned char *) dst;
^ permalink raw reply [flat|nested] 3+ messages in thread
* [U-Boot] [PATCH] Fix gunzip in case of insufficient output buffer
2009-01-02 14:11 [U-Boot] [PATCH] Fix gunzip in case of insufficient output buffer Matthias Fuchs
2009-01-19 12:21 ` Matthias Fuchs
@ 2009-01-27 19:59 ` Wolfgang Denk
1 sibling, 0 replies; 3+ messages in thread
From: Wolfgang Denk @ 2009-01-27 19:59 UTC (permalink / raw)
To: u-boot
Dear Matthias Fuchs,
In message <200901021511.42036.matthias.fuchs@esd-electronics.com> you wrote:
> U-Boot's gunzip() function does not handle the return code
> of zlib's inflate() function correctly. gunzip() is implemented
> to uncompress all input data in one run. So the correct return
> code for the good case is Z_STREAM_END. In case of insufficient
> output buffer memory inflate returns Z_OK. For gunzip() this
> is an error.
>
> It also makes sense to me to call inflateEnd() also in case
> of an error.
>
> Signed-off-by: Matthias Fuchs <matthias.fuchs@esd-electronics.com>
> ---
> common/cmd_bootm.c | 2 +-
> lib_generic/gunzip.c | 3 ++-
> 2 files changed, 3 insertions(+), 2 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
HEALTH WARNING: Care Should Be Taken When Lifting This Product, Since
Its Mass, and Thus Its Weight, Is Dependent on Its Velocity Relative
to the User.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-01-27 19:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-02 14:11 [U-Boot] [PATCH] Fix gunzip in case of insufficient output buffer Matthias Fuchs
2009-01-19 12:21 ` Matthias Fuchs
2009-01-27 19:59 ` Wolfgang Denk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox