Heap buffer overflow in extractContigSamples32bits, tiffcrop.c:3144
Summary
There is a heap buffer overflow in tiffcrop, extractContigSamples32bits. tiffcrop.c:3144, which could lead to denial of service.
Version
LIBTIFF, Version 4.3.0, commit 2a7f438d
Steps to reproduce
Compile with flag
-O0 -g -fsanitize=address
Run
./tiffcrop -i poc /dev/null
Here is the trace reported by ASAN:
==106803==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000257 at pc 0x00000052e263 bp 0x7fff7e2255c0 sp 0x7fff7e2255b8
READ of size 1 at 0x602000000257 thread T0
#0 0x52e262 in extractContigSamples32bits /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c
#1 0x52b3ec in extractContigSamplesToBuffer /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:3629:19
#2 0x52b3ec in writeBufferToSeparateStrips /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:1220:11
#3 0x51c40f in writeCroppedImage /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:8037:11
#4 0x5078a3 in main /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:2424:15
#5 0x7f975d6ed83f in __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:291
#6 0x41c828 in _start (/mnt/data/playground/libtiff/build-bug/tools/tiffcrop+0x41c828)
0x602000000257 is located 0 bytes to the right of 7-byte region [0x602000000250,0x602000000257)
allocated by thread T0 here:
#0 0x4afc22 in malloc /dependence/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:145
#1 0x5bf734 in _TIFFmalloc /mnt/data/playground/libtiff/build-bug/libtiff/../../libtiff/tif_unix.c:314:10
SUMMARY: AddressSanitizer: heap-buffer-overflow /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c in extractContigSamples32bits
Shadow bytes around the buggy address:
0x0c047fff7ff0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff8000: fa fa 00 00 fa fa fd fa fa fa fd fa fa fa fd fa
0x0c047fff8010: fa fa fd fd fa fa 00 01 fa fa fd fa fa fa 02 fa
0x0c047fff8020: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
0x0c047fff8030: fa fa 06 fa fa fa fd fd fa fa fd fa fa fa fd fa
=>0x0c047fff8040: fa fa fd fa fa fa fd fa fa fa[07]fa fa fa 00 01
0x0c047fff8050: fa fa 06 fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8060: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==106803==ABORTING
Platform
DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"