Heap buffer overflow in reverseSamples16bits, tiffcrop.c
Summary
There is a heap buffer overflow in tiffcrop, reverseSamples16bits. tiffcrop.c, 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:
==126173==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f2db3cfe97e at pc 0x000000524fee bp 0x7fffc6ad9050 sp 0x7fffc6ad9048
READ of size 1 at 0x7f2db3cfe97e thread T0
#0 0x524fed in reverseSamples16bits /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c
#1 0x5218f2 in mirrorImage /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:9142:33
#2 0x4fccc1 in correct_orientation /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:6291:9
#3 0x4fccc1 in main /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:2386:6
#4 0x7f2db6ff183f in __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:291
#5 0x41c828 in _start (/mnt/data/playground/libtiff/build-bug/tools/tiffcrop+0x41c828)
0x7f2db3cfe97e is located 11 bytes to the right of 1147251-byte region [0x7f2db3be6800,0x7f2db3cfe973)
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
#2 0x4fca92 in main /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:2376:11
#3 0x7f2db6ff183f in __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: heap-buffer-overflow /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c in reverseSamples16bits
Shadow bytes around the buggy address:
0x0fe636797cd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0fe636797ce0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0fe636797cf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0fe636797d00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0fe636797d10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0fe636797d20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03[fa]
0x0fe636797d30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0fe636797d40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0fe636797d50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0fe636797d60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0fe636797d70: 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
==126173==ABORTING
Platform
DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"