diff options
author | Phillip Lougher <phillip@squashfs.org.uk> | 2013-01-23 19:09:32 +0000 |
---|---|---|
committer | Phillip Lougher <phillip@squashfs.org.uk> | 2013-01-23 19:09:32 +0000 |
commit | 43a2774b2e8013b39c51d316e0f7b5b2ffb730a3 (patch) | |
tree | a4441d6445ce8623436aa25feb5b5f508b917ea0 /squashfs-tools | |
parent | bda1cd91543aca995702255be85acf84f2e94f54 (diff) | |
download | squashfs-tools-43a2774b2e8013b39c51d316e0f7b5b2ffb730a3.tar.gz |
codec_wrappers: rename block_size in uncompress() to outsize
Rename block_size parameter in uncompress() call to outsize, as it
now holds the size of the output buffer, which can be less than
block_size.
Also in the wrappers where the uncompressed length is available
in the header, don't bother calling the codec if outsize is too
small.
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
Diffstat (limited to 'squashfs-tools')
-rw-r--r-- | squashfs-tools/gzip_wrapper.c | 6 | ||||
-rw-r--r-- | squashfs-tools/lzma_wrapper.c | 9 | ||||
-rw-r--r-- | squashfs-tools/lzma_xz_wrapper.c | 12 | ||||
-rw-r--r-- | squashfs-tools/lzo_wrapper.c | 6 | ||||
-rw-r--r-- | squashfs-tools/xz_wrapper.c | 6 |
5 files changed, 25 insertions, 14 deletions
diff --git a/squashfs-tools/gzip_wrapper.c b/squashfs-tools/gzip_wrapper.c index 556f1e8..00f4817 100644 --- a/squashfs-tools/gzip_wrapper.c +++ b/squashfs-tools/gzip_wrapper.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 + * Copyright (c) 2009, 2010, 2013 * Phillip Lougher <phillip@squashfs.org.uk> * * This program is free software; you can redistribute it and/or @@ -87,10 +87,10 @@ failed: } -static int gzip_uncompress(void *d, void *s, int size, int block_size, int *error) +static int gzip_uncompress(void *d, void *s, int size, int outsize, int *error) { int res; - unsigned long bytes = block_size; + unsigned long bytes = outsize; res = uncompress(d, &bytes, s, size); diff --git a/squashfs-tools/lzma_wrapper.c b/squashfs-tools/lzma_wrapper.c index c7d6bd8..87feb46 100644 --- a/squashfs-tools/lzma_wrapper.c +++ b/squashfs-tools/lzma_wrapper.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010 + * Copyright (c) 2009, 2010, 2013 * Phillip Lougher <phillip@squashfs.org.uk> * * This program is free software; you can redistribute it and/or @@ -79,7 +79,7 @@ static int lzma_compress(void *strm, void *dest, void *src, int size, int block_ } -static int lzma_uncompress(void *dest, void *src, int size, int block_size, +static int lzma_uncompress(void *dest, void *src, int size, int outsize, int *error) { unsigned char *s = src; @@ -91,6 +91,11 @@ static int lzma_uncompress(void *dest, void *src, int size, int block_size, (s[LZMA_PROPS_SIZE + 2] << 16) | (s[LZMA_PROPS_SIZE + 3] << 24); + if(outlen > outsize) { + *error = 0; + return -1; + } + res = LzmaUncompress(dest, &outlen, src + LZMA_HEADER_SIZE, &inlen, src, LZMA_PROPS_SIZE); diff --git a/squashfs-tools/lzma_xz_wrapper.c b/squashfs-tools/lzma_xz_wrapper.c index 6db0423..55a6813 100644 --- a/squashfs-tools/lzma_xz_wrapper.c +++ b/squashfs-tools/lzma_xz_wrapper.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 + * Copyright (c) 2010, 2013 * Phillip Lougher <phillip@squashfs.org.uk> * * This program is free software; you can redistribute it and/or @@ -96,7 +96,7 @@ failed: } -static int lzma_uncompress(void *dest, void *src, int size, int block_size, +static int lzma_uncompress(void *dest, void *src, int size, int outsize, int *error) { lzma_stream strm = LZMA_STREAM_INIT; @@ -114,10 +114,16 @@ static int lzma_uncompress(void *dest, void *src, int size, int block_size, (lzma_header[LZMA_PROPS_SIZE + 1] << 8) | (lzma_header[LZMA_PROPS_SIZE + 2] << 16) | (lzma_header[LZMA_PROPS_SIZE + 3] << 24); + + if(uncompressed_size > outsize) { + res = 0; + goto failed; + } + memset(lzma_header + LZMA_PROPS_SIZE, 255, LZMA_UNCOMP_SIZE); strm.next_out = dest; - strm.avail_out = block_size; + strm.avail_out = outsize; strm.next_in = lzma_header; strm.avail_in = LZMA_HEADER_SIZE; diff --git a/squashfs-tools/lzo_wrapper.c b/squashfs-tools/lzo_wrapper.c index 8ee58ed..b42e29b 100644 --- a/squashfs-tools/lzo_wrapper.c +++ b/squashfs-tools/lzo_wrapper.c @@ -2,7 +2,7 @@ * Copyright (c) 2010 LG Electronics * Chan Jeong <chan.jeong@lge.com> * - * All modifications Copyright (c) 2010 + * All modifications Copyright (c) 2010, 2013 * Phillip Lougher <phillip@squashfs.org.uk> * * This program is free software; you can redistribute it and/or @@ -97,10 +97,10 @@ failed: } -static int lzo_uncompress(void *d, void *s, int size, int block_size, int *error) +static int lzo_uncompress(void *d, void *s, int size, int outsize, int *error) { int res; - lzo_uint bytes = block_size; + lzo_uint bytes = outsize; res = lzo1x_decompress_safe(s, size, d, &bytes, NULL); diff --git a/squashfs-tools/xz_wrapper.c b/squashfs-tools/xz_wrapper.c index 03a17d2..8c2ab1c 100644 --- a/squashfs-tools/xz_wrapper.c +++ b/squashfs-tools/xz_wrapper.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, 2011, 2012 + * Copyright (c) 2010, 2011, 2012, 2013 * Phillip Lougher <phillip@squashfs.org.uk> * * This program is free software; you can redistribute it and/or @@ -433,7 +433,7 @@ failed: } -static int xz_uncompress(void *dest, void *src, int size, int block_size, +static int xz_uncompress(void *dest, void *src, int size, int outsize, int *error) { size_t src_pos = 0; @@ -441,7 +441,7 @@ static int xz_uncompress(void *dest, void *src, int size, int block_size, uint64_t memlimit = MEMLIMIT; lzma_ret res = lzma_stream_buffer_decode(&memlimit, 0, NULL, - src, &src_pos, size, dest, &dest_pos, block_size); + src, &src_pos, size, dest, &dest_pos, outsize); *error = res; return res == LZMA_OK && size == (int) src_pos ? (int) dest_pos : -1; |