Menu

#305 Heap buffer overflow in PluginPNM.cpp:353

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

Heap buffer overflow in PluginPNM.cpp:353

Summary:

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

Version Affected:

3.19.0 (r1828)

ASAN Details

==17712==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7f3653c95830 at pc 0x5650400c2eac bp 0x7ffdb0eb6210 sp 0x7ffdb0eb6200
READ of size 1 at 0x7f3653c95830 thread T0
    #0 0x5650400c2eab in Load Source/FreeImage/PluginPNM.cpp:353
    #1 0x56503ffee47b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
    #2 0x56503ffee47b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
    #3 0x56503ffee952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
    #4 0x56503ffa912b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16
    #5 0x7f36568a4b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
    #6 0x56503ffb9f69 in _start (/home/lab4/src/freeimage-svn/FreeImage/trunk/load-test+0x149f69)

0x7f3653c95830 is located 0 bytes to the right of 53141552-byte region [0x7f36509e7800,0x7f3653c95830)
allocated by thread T0 here:
    #0 0x7f3656ebf448 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c448)
    #1 0x56503ffbfa50 in FreeImage_Aligned_Malloc(unsigned long, unsigned long) Source/FreeImage/BitmapAccess.cpp:183
    #2 0x56503ffbfa50 in FreeImage_AllocateBitmap Source/FreeImage/BitmapAccess.cpp:390
    #3 0x56503ffbfa50 in FreeImage_AllocateHeader Source/FreeImage/BitmapAccess.cpp:482
    #4 0x5650400c0471 in Load Source/FreeImage/PluginPNM.cpp:263
    #5 0x56503ffee47b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
    #6 0x56503ffee47b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
    #7 0x56503ffee952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
    #8 0x56503ffa912b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16

SUMMARY: AddressSanitizer: heap-buffer-overflow Source/FreeImage/PluginPNM.cpp:353 in Load
Shadow bytes around the buggy address:
  0x0fe74a78aab0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe74a78aac0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe74a78aad0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe74a78aae0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0fe74a78aaf0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0fe74a78ab00: 00 00 00 00 00 00[fa]fa fa fa fa fa fa fa fa fa
  0x0fe74a78ab10: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0fe74a78ab20: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0fe74a78ab30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0fe74a78ab40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0fe74a78ab50: 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
==17712==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_PluginPNM_353

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.