Menu

#303 Heap buffer overflow in PluginPCX.cpp:573

None
pending
7
2021-04-04
2020-02-13
freeKim
No

Heap buffer overflow in PluginPCX.cpp:573

Summary:

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

Version Affected: 3.19(r)

ASAN Details

=================================================================
==15876==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000040 at pc 0x55997b80b535 bp 0x7fff02309ba0 sp 0x7fff02309b90
READ of size 1 at 0x602000000040 thread T0
    #0 0x55997b80b534 in Load Source/FreeImage/PluginPCX.cpp:573
    #1 0x55997b76547b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
    #2 0x55997b76547b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
    #3 0x55997b765952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
    #4 0x55997b72012b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16
    #5 0x7fc82fa5fb6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
    #6 0x55997b730f69 in _start (/home/lab4/src/freeimage-svn/FreeImage/trunk/load-test+0x149f69)

0x602000000040 is located 0 bytes to the right of 16-byte region [0x602000000030,0x602000000040)
allocated by thread T0 here:
    #0 0x7fc83007a448 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c448)
    #1 0x55997b806239 in Load Source/FreeImage/PluginPCX.cpp:514
    #2 0x55997b76547b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
    #3 0x55997b76547b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
    #4 0x55997b765952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
    #5 0x55997b72012b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16

SUMMARY: AddressSanitizer: heap-buffer-overflow Source/FreeImage/PluginPCX.cpp:573 in Load
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 00 00[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
==15876==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_PluginPCX_573

Credit

ADLab of Venustech

1 Attachments

Discussion

  • Hervé Drolon

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

Log in to post a comment.