Commit 107b801c authored by Matthias Fuchs's avatar Matthias Fuchs Committed by Wolfgang Denk

Fix gunzip in case of insufficient output buffer

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: default avatarMatthias Fuchs <matthias.fuchs@esd-electronics.com>
parent 49ad4801
......@@ -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);
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment