X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=lib%2Fgunzip.c;h=bee3b9261f3449c438c43fac77bac45cde127238;hb=0d8f35b58cc8458a5263b424896a386429ee49e5;hp=6d65ccccffa018582ed33497f5ae9361c6252f23;hpb=e6de55ec5bf306df3b3cc8e7a4cc17fa1e78ca6c;p=oweals%2Fu-boot.git diff --git a/lib/gunzip.c b/lib/gunzip.c index 6d65ccccff..bee3b9261f 100644 --- a/lib/gunzip.c +++ b/lib/gunzip.c @@ -1,18 +1,21 @@ +// 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 #include -#include #define HEADER0 '\x1f' #define HEADER1 '\x8b' @@ -41,7 +44,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; @@ -62,12 +65,21 @@ 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 @@ -193,7 +205,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 { @@ -232,9 +244,8 @@ int gzwrite(unsigned char *src, int len, gzwrite_progress(iteration++, totalfilled, szexpected); - blocks_written = dev->block_write(dev, outblock, - writeblocks, - writebuf); + blocks_written = blk_dwrite(dev, outblock, + writeblocks, writebuf); outblock += blocks_written; if (ctrlc()) { puts("abort\n");