Heap buffer overflow in tiffcp() at tiffcp.c:784
Heap buffer overflow in the libtiff at function tiffcp in tiffcp.c:784.
Environment
Ubuntu 18.04, 64 bit
libtiff-Release-v4-0-7
Steps to reproduce
- download file
wget https://github.com/vadz/libtiff/archive/refs/tags/Release-v4-0-7.tar.gz
tar -zxvf Release-v4-0-7.tar.gz
- compile libming with ASAN
cd libtiff-Release-v4-0-7
./autogen.sh
CC=clang CXX=clang++ CFLAGS="-fsanitize=address -g -O0 -Wno-error" ./configure --prefix=`pwd`/obj-bc --disable-shared
make
make install
cd obj-bc/bin/
- command for reproducing the error
./tiffcp -i poc /tmp/temp
Download poc: libtiff_0-4-7_tiffcp_heap-buffer-overflow_tiffcp784.zip
ASAN report
root@2413df779df0:~/compiler1804/reportCVEs/libtiff-Release-v4-0-7/obj-bc/bin# ./tiffcp -i libtiff_0-4-7_tiffcp_heap-buffer-overflow_tiffcp784.tiff /tmp/temp
TIFFReadDirectoryCheckOrder: Warning, Invalid TIFF directory; tags are not sorted in ascending order.
TIFFReadDirectory: Warning, Unknown field with tag 6656 (0x1a00) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 23552 (0x5c00) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 4 (0x4) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 260 (0x104) encountered.
_TIFFVSetField: libtiff_0-4-7_tiffcp_heap-buffer-overflow_tiffcp784.tiff: Null count for "Tag 6656" (type 1, writecount -3, passcount 1).
TIFFFetchNormalTag: Warning, IO error during reading of "Tag 4"; tag ignored.
TIFFFetchNormalTag: Warning, Sanity check on size of "Tag 260" value failed; tag ignored.
TIFFFetchNormalTag: Warning, ASCII value for tag "InkNames" does not end in null byte. Forcing it to be null.
TIFFFetchNormalTag: Warning, Incorrect count for "YResolution"; tag ignored.
TIFFReadDirectory: Warning, TIFF directory is missing required "StripByteCounts" field, calculating from imagelength.
=================================================================
==7700==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6020000001b1 at pc 0x0000004398c4 bp 0x7fffd8881a90 sp 0x7fffd8881240
READ of size 1 at 0x6020000001b1 thread T0
#0 0x4398c3 in __interceptor_strlen.part.36 /root/LLVM/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:372
#1 0x4f70eb in tiffcp /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/tools/tiffcp.c:784:57
#2 0x4f4f03 in main /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/tools/tiffcp.c:304:9
#3 0x7fca967cac86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
#4 0x41bd09 in _start (/root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/obj-bc/bin/tiffcp+0x41bd09)
0x6020000001b1 is located 0 bytes to the right of 1-byte region [0x6020000001b0,0x6020000001b1)
allocated by thread T0 here:
#0 0x4ae320 in malloc /root/LLVM/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cpp:145
#1 0x58b43c in _TIFFmalloc /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_unix.c:316:10
#2 0x505884 in setByteArray /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_dir.c:53:19
#3 0x524dd9 in _TIFFsetNString /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_dir.c:63:7
#4 0x511014 in _TIFFVSetField /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_dir.c:460:4
#5 0x505d53 in TIFFVSetField /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_dir.c:844:6
#6 0x505c63 in TIFFSetField /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_dir.c:788:11
#7 0x536394 in TIFFFetchNormalTag /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_dirread.c:5008:9
#8 0x52cc7b in TIFFReadDirectory /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_dirread.c:3821:12
#9 0x570635 in TIFFClientOpen /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_open.c:466:8
#10 0x589fff in TIFFFdOpen /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_unix.c:211:8
#11 0x58b3d4 in TIFFOpen /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/libtiff/tif_unix.c:250:8
#12 0x4f568a in openSrcImage /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/tools/tiffcp.c:153:9
#13 0x4f4dae in main /root/compiler1804/reportCVEs/libtiff-Release-v4-0-7/tools/tiffcp.c:282:8
#14 0x7fca967cac86 in __libc_start_main /build/glibc-CVJwZb/glibc-2.27/csu/../csu/libc-start.c:310
SUMMARY: AddressSanitizer: heap-buffer-overflow /root/LLVM/llvm/projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:372 in __interceptor_strlen.part.36
Shadow bytes around the buggy address:
0x0c047fff7fe0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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 04 fa
0x0c047fff8010: fa fa fd fa fa fa fd fd fa fa 00 fa fa fa fd fa
0x0c047fff8020: fa fa fd fa fa fa 00 fa fa fa 02 fa fa fa fd fa
=>0x0c047fff8030: fa fa fd fa fa fa[01]fa fa fa 00 fa fa fa 02 fa
0x0c047fff8040: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8050: fa fa fa 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
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
==7700==ABORTING