X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Fgunzip.c;h=1d65616c13d4ded7dd84b302fbe8f9e12cae9d01;hb=24b77393a5fcc3e1f51b4e3a1080c0efb60b52eb;hp=4128a1871c998836dde4bded2c6784d2b1826768;hpb=5f757cdcc6efbefec09b8f964a234f84ff9fa7f6;p=oweals%2Fu-boot.git diff --git a/lib/gunzip.c b/lib/gunzip.c index 4128a1871c..1d65616c13 100644 --- a/lib/gunzip.c +++ b/lib/gunzip.c @@ -1,17 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * (C) Copyright 2000-2006 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. - * - * SPDX-License-Identifier: GPL-2.0+ */ #include -#include #include +#include +#include +#include #include #include +#include +#include #include -#include #define HEADER0 '\x1f' #define HEADER1 '\x8b' @@ -40,7 +42,7 @@ void gzfree(void *x, void *addr, unsigned nb) free (addr); } -int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) +int gzip_parse_header(const unsigned char *src, unsigned long len) { int i, flags; @@ -61,14 +63,24 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) ; if ((flags & HEAD_CRC) != 0) i += 2; - if (i >= *lenp) { + if (i >= len) { puts ("Error: gunzip out of data in header\n"); return (-1); } + return i; +} + +int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) +{ + int offset = gzip_parse_header(src, *lenp); + + if (offset < 0) + return offset; - return zunzip(dst, dstlen, src, lenp, 1, i); + return zunzip(dst, dstlen, src, lenp, 1, offset); } +#ifdef CONFIG_CMD_UNZIP __weak void gzwrite_progress_init(u64 expectedsize) { @@ -103,7 +115,7 @@ void gzwrite_progress_finish(int returnval, } int gzwrite(unsigned char *src, int len, - struct block_dev_desc *dev, + struct blk_desc *dev, unsigned long szwritebuf, u64 startoffs, u64 szexpected) @@ -191,7 +203,7 @@ int gzwrite(unsigned char *src, int len, s.next_in = src + i; s.avail_in = payload_size+8; - writebuf = (unsigned char *)malloc(szwritebuf); + writebuf = (unsigned char *)malloc_cache_aligned(szwritebuf); /* decompress until deflate stream ends or end of file */ do { @@ -230,10 +242,8 @@ int gzwrite(unsigned char *src, int len, gzwrite_progress(iteration++, totalfilled, szexpected); - blocks_written = dev->block_write(dev->dev, - outblock, - writeblocks, - writebuf); + blocks_written = blk_dwrite(dev, outblock, + writeblocks, writebuf); outblock += blocks_written; if (ctrlc()) { puts("abort\n"); @@ -258,6 +268,7 @@ out: return r; } +#endif /* * Uncompress blocks compressed with zlib without headers @@ -284,12 +295,11 @@ int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, do { r = inflate(&s, Z_FINISH); if (stoponerr == 1 && r != Z_STREAM_END && - (s.avail_out == 0 || r != Z_BUF_ERROR)) { + (s.avail_in == 0 || s.avail_out == 0 || r != Z_BUF_ERROR)) { printf("Error: inflate() returned %d\n", r); err = -1; break; } - s.avail_in = *lenp - offset - (int)(s.next_out - (unsigned char*)dst); } while (r == Z_BUF_ERROR); *lenp = s.next_out - (unsigned char *) dst; inflateEnd(&s);