mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-30 08:31:03 +00:00
1934665742
Current, the following passes: ./u-boot -d arch/sandbox/dts/test.dtb -c 'ut_image_decomp' but the following fails: ./u-boot -d arch/sandbox/dts/test.dtb -c 'ut dm; ut_image_decomp' This is because the gunzip code reads input data beyond the end of its input buffer. In the first case above, this data just happens to be 0, which just happens to trigger gzip to signal the error the decompression unit test expects. In the second case above, the "ut dm" test has written data to the accidentally-read memory, which causes the gzip code to take a different path and so return a different value, which triggers the test failure. The cause of gunzip reading past its input buffer is the re-calculation of s.avail_in in zunzip(), since it can underflow. Not only is the formula non-sensical (it uses the delta between two output buffer pointers to calculate available input buffer size), it also appears to be unnecessary, since the gunzip code already maintains this value itself. This patch removes this re-calculation to avoid the underflow and redundant work. The loop exit condition is also adjusted so that if inflate() has consumed the entire input buffer, without indicating returning Z_STREAM_END (i.e. decompression complete without error), an error is raised. There is still opportunity to simplify the code here by splitting up the loop exit condition into separate tests. However, this patch makes the minimum modifications required to solve the problem at hand, in order to keep the Acked-by: Kees Cook <keescook@chromium.org> diff simple. I am not entirely convinced that the loop in zunzip() is necessary at all. It could only be useful if inflate() can return Z_BUF_ERROR (which typically means that it needs more data in the input buffer, or more space in the output buffer), even though Z_FINISH is set /and/ the full input is available in the input buffer /and/ there is enough space to store the decompressed output in the output buffer. The comment in zlib.h after the prototype of inflate() implies this is never the case. However, I assume there must have been some reason for introducing this loop in the first place, as part of commit "Fix gunzip to work for any gziped uImage size". This patch is similar to the earlier |
||
---|---|---|
.. | ||
bzip2 | ||
dhry | ||
efi | ||
libfdt | ||
lzma | ||
lzo | ||
rsa | ||
tizen | ||
zlib | ||
addr_map.c | ||
aes.c | ||
asm-offsets.c | ||
bch.c | ||
bitrev.c | ||
circbuf.c | ||
crc7.c | ||
crc8.c | ||
crc16.c | ||
crc32.c | ||
ctype.c | ||
display_options.c | ||
div64.c | ||
errno.c | ||
errno_str.c | ||
fdtdec.c | ||
fdtdec_common.c | ||
fdtdec_test.c | ||
gunzip.c | ||
gzip.c | ||
hang.c | ||
hashtable.c | ||
initcall.c | ||
Kconfig | ||
ldiv.c | ||
linux_compat.c | ||
linux_string.c | ||
list_sort.c | ||
lmb.c | ||
lz4.c | ||
lz4_wrapper.c | ||
Makefile | ||
md5.c | ||
membuff.c | ||
net_utils.c | ||
panic.c | ||
physmem.c | ||
qsort.c | ||
rand.c | ||
rbtree.c | ||
rc4.c | ||
sha1.c | ||
sha256.c | ||
slre.c | ||
string.c | ||
strmhz.c | ||
strto.c | ||
time.c | ||
tiny-printf.c | ||
tpm.c | ||
trace.c | ||
uuid.c | ||
vsprintf.c |