There is a heap buffer overflow in PluginTARGA.cpp(line 558) while loading image with FreeImage_Load function。
==21450==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000030 at pc 0x556122904891 bp 0x7ffee1ccf9c0 sp 0x7ffee1ccf9b0
READ of size 4 at 0x602000000030 thread T0
#0 0x556122904890 in _assignPixel<32> Source/FreeImage/PluginTARGA.cpp:558
#1 0x556122904890 in loadRLE<32> Source/FreeImage/PluginTARGA.cpp:630
#2 0x556122904890 in Load Source/FreeImage/PluginTARGA.cpp:1050
#3 0x55612280547b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
#4 0x55612280547b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
#5 0x556122805952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
#6 0x5561227c012b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16
#7 0x7f706e2f6b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
#8 0x5561227d0f69 in _start (/home/lab4/src/freeimage-svn/FreeImage/trunk/load-test+0x149f69)
0x602000000031 is located 0 bytes to the right of 1-byte region [0x602000000030,0x602000000031)
allocated by thread T0 here:
#0 0x7f706e911448 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c448)
#1 0x5561228fb8d5 in IOCache::IOCache(FreeImageIO*, void*, unsigned long) Source/FreeImage/PluginTARGA.cpp:214
#2 0x5561228fb8d5 in loadRLE<32> Source/FreeImage/PluginTARGA.cpp:594
#3 0x5561228fb8d5 in Load Source/FreeImage/PluginTARGA.cpp:1050
#4 0x55612280547b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
#5 0x55612280547b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
#6 0x556122805952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
#7 0x5561227c012b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16
SUMMARY: AddressSanitizer: heap-buffer-overflow Source/FreeImage/PluginTARGA.cpp:558 in _assignPixel<32>
Shadow bytes around the buggy address:
0x0c047fff7fb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fc0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c047fff7fd0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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 fa fa fa[01]fa fa fa fa fa fa fa fa fa
0x0c047fff8010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8020: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c047fff8030: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 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
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
==21450==ABORTING
Aborted
To reproduce it ,compile FreeImage with ASAN. Then compile and execute the test file in the attachment as follows:
Clang++ -g -fsanitize=address load-test.c -lfreeimage -L. -lm -o load-test
./load-test oob_read_PluginTARGA_558
ADLab of Venustech
see https://sourceforge.net/p/freeimage/patches/142/