Heap buffer overflow in _TIFFmemcpy, tif_unix.c:346
Summary
There is a heap buffer overflow in tiffcrop, _TIFFmemcpy. tif_unix.c:346, caused by copying an excessive memory without checking its size, 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:
==178056==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7fa3a21ffffc at pc 0x0000004aeb85 bp 0x7ffcf8c36740 sp 0x7ffcf8c35ef0
READ of size 14 at 0x7fa3a21ffffc thread T0
#0 0x4aeb84 in __asan_memcpy /dependence/llvm-project/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp:22
#1 0x5bf8da in _TIFFmemcpy /mnt/data/playground/libtiff/build-bug/libtiff/../../libtiff/tif_unix.c:346:2
#2 0x5214ec in mirrorImage /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:9097:8
#3 0x4fccc1 in correct_orientation /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:6291:9
#4 0x4fccc1 in main /mnt/data/playground/libtiff/build-bug/tools/../../tools/tiffcrop.c:2386:6
#5 0x7fa3a4e7783f 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)
0x7fa3a21ffffc is located 5387 bytes to the right of 856817-byte region [0x7fa3a212d800,0x7fa3a21feaf1)
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 0x7fa3a4e7783f in __libc_start_main /build/glibc-S7Ft5T/glibc-2.23/csu/../csu/libc-start.c:291
SUMMARY: AddressSanitizer: heap-buffer-overflow /dependence/llvm-project/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp:22 in __asan_memcpy
Shadow bytes around the buggy address:
0x0ff4f4437fa0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff4f4437fb0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff4f4437fc0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff4f4437fd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0ff4f4437fe0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0ff4f4437ff0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa[fa]
0x0ff4f4438000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff4f4438010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff4f4438020: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff4f4438030: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0ff4f4438040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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
==178056==ABORTING
Platform
DISTRIB_ID=Ubuntu DISTRIB_RELEASE=16.04 DISTRIB_CODENAME=xenial DISTRIB_DESCRIPTION="Ubuntu 16.04.6 LTS"
Edited by Doudou Huang