tiffcrop: heap-buffer-overflow in extractContigSamplesShifted16bits, tiffcrop.c:3502
Summary
There is heap-buffer-overflow errors in extractContigSamplesShifted16bits in tools/tiffcrop.c:3502. Remote attackers could leverage this vulnerability to cause a denial-of-service via a crafted tiff file.
Version
LIBTIFF, Version master (post 4.4.0), commit id 1bdbd03f (Tue Nov 29 17:02:09 2022 +0000)
Steps to reproduce
# CFLAGS="-g -fsanitize=address -fno-omit-frame-pointer" CXXFLAGS="-g -fsanitize=address -fno-omit-frame-pointer" ./configure --prefix=$PWD/build_asan --disable-shared
# make -j; make install; make clean
$ ./build_asan/bin/tiffcrop -E right -z 1,1,2048,2048:1,2049,2048,4097 poc /tmp/foo
=================================================================
==145235==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x62d000009400 at pc 0x560d0cad3aa0 bp 0x7fff1efaf900 sp 0x7fff1efaf8f0
WRITE of size 1 at 0x62d000009400 thread T0
#0 0x560d0cad3a9f in extractContigSamplesShifted16bits /root/programs_latest/libtiff/tools/tiffcrop.c:3502
#1 0x560d0cae9251 in extractCompositeRegions /root/programs_latest/libtiff/tools/tiffcrop.c:6801
#2 0x560d0caecd0a in processCropSelections /root/programs_latest/libtiff/tools/tiffcrop.c:7733
#3 0x560d0cacfbb1 in main /root/programs_latest/libtiff/tools/tiffcrop.c:2511
#4 0x7f5717d63082 in __libc_start_main ../csu/libc-start.c:308
#5 0x560d0cac660d in _start (/root/programs_latest/libtiff/build_asan/bin/tiffcrop+0x2e60d)
0x62d000009400 is located 1021 bytes to the right of 35843-byte region [0x62d000000400,0x62d000009003)
allocated by thread T0 here:
#0 0x7f571870b808 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cc:144
#1 0x560d0cb6909e in _TIFFmalloc /root/programs_latest/libtiff/libtiff/tif_unix.c:336
#2 0x560d0cac67a0 in limitMalloc /root/programs_latest/libtiff/tools/tiffcrop.c:644
#3 0x560d0caeca81 in processCropSelections /root/programs_latest/libtiff/tools/tiffcrop.c:7705
#4 0x560d0cacfbb1 in main /root/programs_latest/libtiff/tools/tiffcrop.c:2511
#5 0x7f5717d63082 in __libc_start_main ../csu/libc-start.c:308
SUMMARY: AddressSanitizer: heap-buffer-overflow /root/programs_latest/libtiff/tools/tiffcrop.c:3502 in extractContigSamplesShifted16bits
Shadow bytes around the buggy address:
0x0c5a7fff9230: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff9240: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff9250: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff9260: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff9270: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c5a7fff9280:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff9290: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff92a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff92b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff92c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c5a7fff92d0: 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
==145235==ABORTING
Platform
# uname -a
Linux dd189b3c7b86 5.15.0-52-generic #58~20.04.1-Ubuntu SMP Thu Oct 13 13:09:46 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux