tiffcp: AddressSanitizer: global-buffer-overflow /home/lin/libtiff/libtiff/tif_dir.c:1167 in _TIFFVGetField

Summary AddressSanitizer: global-buffer-overflow /home/lin/libtiff/libtiff/tif_dir.c:1167 in _TIFFVGetField

Version

➜  tiffcp_test2 ./tiffcp -v
./tiffcp: invalid option -- 'v'
LIBTIFF, Version 4.3.0
Copyright (c) 1988-1996 Sam Leffler
Copyright (c) 1991-1996 Silicon Graphics, Inc.

At branch 5e180045 (libtiff version)

Steps to reproduce

git clone git@gitlab.com:libtiff/libtiff.git
cd libtiff/
./autogen.sh
./configure CC=gcc CXX=g++ CFLAGS="-g -fsanitize=address" --disable-shared & make
./tools/tiffcp  ./poc ./out2

(How one can reproduce the issue - this is very important)

Platform

➜  libtiff git:(master) ✗ gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

➜  libtiff git:(master) ✗ uname -r
5.4.0-91-generic
➜  libtiff git:(master) ✗ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.5 LTS
Release:	18.04
Codename:	bionic

(Operating system, architecture, compiler details)

  • ASAN
TIFFReadDirectoryCheckOrder: Warning, Invalid TIFF directory; tags are not sorted in ascending order.
TIFFReadDirectory: Warning, Unknown field with tag 62978 (0xf602) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 4352 (0x1100) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 27 (0x1b) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 317 (0x13d) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 228 (0xe4) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 25600 (0x6400) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 19240 (0x4b28) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 19275 (0x4b4b) encountered.
TIFFFetchNormalTag: Warning, Incorrect count for "FillOrder"; tag ignored.
TIFFFetchNormalTag: Warning, Sanity check on size of "DocumentName" value failed; tag ignored.
TIFFFetchNormalTag: Warning, Incorrect count for "Orientation"; tag ignored.
TIFFFetchNormalTag: Warning, IO error during reading of "XResolution"; tag ignored.
./bug/1: ZSTD compression support is not configured.
=================================================================
==118074==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55d1193ea700 at pc 0x55d1192ec517 bp 0x7fffe979b110 sp 0x7fffe979b100
WRITE of size 4 at 0x55d1193ea700 thread T0
    #0 0x55d1192ec516 in _TIFFVGetField /home/lin/libtiff/libtiff/tif_dir.c:1167
    #1 0x55d1192ee218 in TIFFVGetField /home/lin/libtiff/libtiff/tif_dir.c:1305
    #2 0x55d1192ee074 in TIFFGetField /home/lin/libtiff/libtiff/tif_dir.c:1289
    #3 0x55d1192d234f in tiffcp /home/lin/libtiff/tools/tiffcp.c:882
    #4 0x55d1192cff83 in main /home/lin/libtiff/tools/tiffcp.c:334
    #5 0x7fcaff6be0b2 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x270b2)
    #6 0x55d1192ceaad in _start (/home/lin/tiffcp_test2/tiffcp-asan+0x1daad)

0x55d1193ea702 is located 0 bytes to the right of global variable 'predictor' defined in 'tiffcp.c:81:17' (0x55d1193ea700) of size 2
SUMMARY: AddressSanitizer: global-buffer-overflow /home/lin/libtiff/libtiff/tif_dir.c:1167 in _TIFFVGetField
Shadow bytes around the buggy address:
  0x0abaa3275490: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9
  0x0abaa32754a0: f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0abaa32754b0: 00 00 00 00 00 00 00 00 04 f9 f9 f9 f9 f9 f9 f9
  0x0abaa32754c0: 04 f9 f9 f9 f9 f9 f9 f9 02 f9 f9 f9 f9 f9 f9 f9
  0x0abaa32754d0: 02 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
=>0x0abaa32754e0:[02]f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0abaa32754f0: 02 f9 f9 f9 f9 f9 f9 f9 02 f9 f9 f9 f9 f9 f9 f9
  0x0abaa3275500: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0abaa3275510: 04 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
  0x0abaa3275520: 04 f9 f9 f9 f9 f9 f9 f9 04 f9 f9 f9 f9 f9 f9 f9
  0x0abaa3275530: 00 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
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
==118074==ABORTING
  • No Asan
TIFFReadDirectoryCheckOrder: Warning, Invalid TIFF directory; tags are not sorted in ascending order.
TIFFReadDirectory: Warning, Unknown field with tag 62978 (0xf602) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 4352 (0x1100) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 27 (0x1b) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 317 (0x13d) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 228 (0xe4) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 25600 (0x6400) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 19240 (0x4b28) encountered.
TIFFReadDirectory: Warning, Unknown field with tag 19275 (0x4b4b) encountered.
TIFFFetchNormalTag: Warning, Incorrect count for "FillOrder"; tag ignored.
TIFFFetchNormalTag: Warning, Sanity check on size of "DocumentName" value failed; tag ignored.
TIFFFetchNormalTag: Warning, Incorrect count for "Orientation"; tag ignored.
TIFFFetchNormalTag: Warning, IO error during reading of "XResolution"; tag ignored.
./bug/1: ZSTD compression support is not configured.
[1]    118096 segmentation fault (core dumped)  ./tiffcp-no-asan ./bug/1 ./out2

poc: poc.zip

Thanks !!