tiffcrop: SEGV in extractContigSamplesShifted8bits, tiffcrop.c:3400
Summary
There is SEGV errors in extractContigSamplesShifted8bits in tools/tiffcrop.c:3400. 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 multiple -Z 1:4,3:3 -R 270 -i poc /tmp/foo
TIFFReadDirectoryCheckOrder: Warning, Invalid TIFF directory; tags are not sorted in ascending order.
TIFFReadDirectory: Warning, Unknown field with tag 3104 (0xc20) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 32862 (0x805e) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 20343 (0x4f77) encountered.
TIFFFetchNormalTag: Defined set_field_type of custom tag 3104 (Tag 3104) is TIFF_SETGET_UNDEFINED and thus tag is not read from file.
TIFFFetchNormalTag: Defined set_field_type of custom tag 32862 (Tag 32862) is TIFF_SETGET_UNDEFINED and thus tag is not read from file.
TIFFFetchNormalTag: Defined set_field_type of custom tag 20343 (Tag 20343) is TIFF_SETGET_UNDEFINED and thus tag is not read from file.
TIFFFetchNormalTag: Warning, Incorrect count for "XResolution"; tag ignored.
TIFFFetchNormalTag: Warning, IO error during reading of "FaxProfile"; tag ignored.
TIFFReadDirectory: Warning, Ignoring ColorMap since BitsPerSample tag not found.
TIFFFetchStripThing: Warning, Incorrect count for "StripOffsets"; tag ignored.
TIFFFetchStripThing: Warning, Incorrect count for "StripByteCounts"; tag ignored.
loadImage: Image lacks Photometric interpretation tag.
TIFFFillStrip: Read error on strip 0; got 18446744072786805064 bytes, expected 89.
: Strip 1: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 1.
: Strip 2: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 2.
: Strip 3: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 3.
: Strip 4: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 4.
: Strip 5: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 5.
: Strip 6: read -1 bytes, strip size 128.
...
TIFFFillStrip: Invalid strip byte count 0, strip 1418.
: Strip 1419: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 1419.
: Strip 1420: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 1420.
: Strip 1421: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 1421.
: Strip 1422: read -1 bytes, strip size 128.
TIFFFillStrip: Invalid strip byte count 0, strip 1422.
AddressSanitizer:DEADLYSIGNAL
=================================================================
==145128==ERROR: AddressSanitizer: SEGV on unknown address 0x7f8f86b96151 (pc 0x5623ae6ac56c bp 0x7ffe641d7360 sp 0x7ffe641d7300 T0)
==145128==The signal is caused by a READ memory access.
#0 0x5623ae6ac56b in extractContigSamplesShifted8bits /root/programs_latest/libtiff/tools/tiffcrop.c:3400
#1 0x5623ae6c2ad0 in extractSeparateRegion /root/programs_latest/libtiff/tools/tiffcrop.c:6932
#2 0x5623ae6c6a94 in processCropSelections /root/programs_latest/libtiff/tools/tiffcrop.c:7835
#3 0x5623ae6a8bb1 in main /root/programs_latest/libtiff/tools/tiffcrop.c:2511
#4 0x7f8f86c1c082 in __libc_start_main ../csu/libc-start.c:308
#5 0x5623ae69f60d in _start (/root/programs_latest/libtiff/build_asan/bin/tiffcrop+0x2e60d)
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV /root/programs_latest/libtiff/tools/tiffcrop.c:3400 in extractContigSamplesShifted8bits
==145128==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