Menu

#306 Heap buffer overflow in PluginTARGA.cpp:526

None
pending
None
5
2021-04-03
2020-02-13
freeKim
No

Heap buffer overflow in PluginTARGA.cpp:526

Summary:

There is a heap buffer overflow in PluginTARGA.cpp(line 526) while loading image with FreeImage_Load function。

Version Affected: 3.19.0 (r1828)

ASAN Details

==28155==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000030 at pc 0x559e1d0544d3 bp 0x7ffef57d6990 sp 0x7ffef57d6980
READ of size 2 at 0x602000000030 thread T0
    #0 0x559e1d0544d2 in _assignPixel<16> Source/FreeImage/PluginTARGA.cpp:526
    #1 0x559e1d0544d2 in loadRLE<16> Source/FreeImage/PluginTARGA.cpp:630
    #2 0x559e1d0544d2 in Load Source/FreeImage/PluginTARGA.cpp:960
    #3 0x559e1cf5647b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
    #4 0x559e1cf5647b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
    #5 0x559e1cf56952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
    #6 0x559e1cf1112b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16
    #7 0x7fd7bc7b0b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
    #8 0x559e1cf21f69 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 0x7fd7bcdcb448 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c448)
    #1 0x559e1d04b9a9 in IOCache::IOCache(FreeImageIO*, void*, unsigned long) Source/FreeImage/PluginTARGA.cpp:214
    #2 0x559e1d04b9a9 in loadRLE<16> Source/FreeImage/PluginTARGA.cpp:594
    #3 0x559e1d04b9a9 in Load Source/FreeImage/PluginTARGA.cpp:960
    #4 0x559e1cf5647b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
    #5 0x559e1cf5647b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
    #6 0x559e1cf56952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
    #7 0x559e1cf1112b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16

SUMMARY: AddressSanitizer: heap-buffer-overflow Source/FreeImage/PluginTARGA.cpp:526 in _assignPixel<16>
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
==28155==ABORTING
Aborted

Reproduce

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_526

Credit

ADLab of Venustech

1 Attachments

Discussion

  • Hervé Drolon

    Hervé Drolon - 2021-04-03
    • status: open --> pending
    • assigned_to: Hervé Drolon
    • Group: -->
     

Log in to post a comment.