Menu

#320 Heap buffer overflow in function J2KImageToFIBITMAP() in J2KHelper.cpp:133

None
pending
None
5
2021-04-04
2020-03-19
freeKim
No

Heap buffer overflow in function J2KImageToFIBITMAP() in J2KHelper.cpp:133

Summary:

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

Version Affected: 3.19.0 (r1828)

ASAN Details

==24228==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x602000000098 at pc 0x000000c9b91b bp 0x7fffb3f7d730 sp 0x7fffb3f7d728
READ of size 4 at 0x602000000098 thread T0
    #0 0xc9b91a in J2KImageToFIBITMAP(int, opj_image const*, int) /home/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/J2KHelper.cpp:133:28
    #1 0x580cb5 in Load(FreeImageIO*, void*, int, int, void*) /home/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/PluginJ2K.cpp:197:10
    #2 0x5252fc in FreeImage_LoadFromHandle /home/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/Plugin.cpp:388:24
    #3 0x52550c in FreeImage_Load /home/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/Plugin.cpp:408:22
    #4 0x50640c in main /home/src/freeimage-svn/FreeImage/trunk/load-test.c:16:18
    #5 0x7fdc5140db6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
    #6 0x428569 in _start (/home/src/freeimage-svn/FreeImage/trunk/load-test+0x428569)

0x602000000098 is located 7 bytes to the right of 1-byte region [0x602000000090,0x602000000091)
allocated by thread T0 here:
    #0 0x4d3f13 in __interceptor_malloc /build/llvm-toolchain-8-F3l7P1/llvm-toolchain-8-8/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:146:3
    #1 0x8f9c88 in opj_copy_image_header /home/src/freeimage-svn/FreeImage/trunk/Source/LibOpenJPEG/image.c:165:44
    #2 0xdac51b in opj_j2k_read_header /home/src/freeimage-svn/FreeImage/trunk/Source/LibOpenJPEG/j2k.c:6579:9
    #3 0x8fbf02 in opj_read_header /home/src/freeimage-svn/FreeImage/trunk/Source/LibOpenJPEG/openjpeg.c:387:10
    #4 0x5809ba in Load(FreeImageIO*, void*, int, int, void*) /home/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/PluginJ2K.cpp:169:9
    #5 0x5252fc in FreeImage_LoadFromHandle /home/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/Plugin.cpp:388:24
    #6 0x52550c in FreeImage_Load /home/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/Plugin.cpp:408:22
    #7 0x50640c in main /home/src/freeimage-svn/FreeImage/trunk/load-test.c:16:18
    #8 0x7fdc5140db6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)

SUMMARY: AddressSanitizer: heap-buffer-overflow /home/src/freeimage-svn/FreeImage/trunk/Source/FreeImage/J2KHelper.cpp:133:28 in J2KImageToFIBITMAP(int, opj_image const*, int)
Shadow bytes around the buggy address:
  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 fd fd fa fa fd fd fa fa fd fa fa fa fd fa
=>0x0c047fff8010: fa fa 01[fa]fa fa fd fa fa fa fd 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
  0x0c047fff8060: 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
==24228==ABORTING

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_J2KHelper_cpp_133

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.

MongoDB Logo MongoDB