Menu

#313 Heap buffer overflow in j2k.c:7110

open
nobody
None
5
2020-02-14
2020-02-14
freeKim
No

Heap buffer overflow in j2k.c:7110

Summary:

There is a heap buffer overflow in j2k.c(line 7110) while loading image with FreeImage_Load function。

Version Affected: 3.19.0 (r1828)

ASAN Details

==23845==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x612000000310 at pc 0x561b936ac8d5 bp 0x7ffe0c9c33a0 sp 0x7ffe0c9c3390
READ of size 8 at 0x612000000310 thread T0
    #0 0x561b936ac8d4 in opj_j2k_copy_default_tcp_and_create_tcd Source/LibOpenJPEG/j2k.c:7110
    #1 0x561b936ad050 in opj_j2k_exec Source/LibOpenJPEG/j2k.c:7035
    #2 0x561b936c9cbc in opj_j2k_read_header Source/LibOpenJPEG/j2k.c:6567
    #3 0x561b92a443dd in Load Source/FreeImage/PluginJ2K.cpp:169
    #4 0x561b929d147b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
    #5 0x561b929d147b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
    #6 0x561b929d1952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
    #7 0x561b9298c12b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16
    #8 0x7f4827ea7b6a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x26b6a)
    #9 0x561b9299cf69 in _start (/home/lab4/src/freeimage-svn/FreeImage/trunk/load-test+0x149f69)

0x612000000310 is located 16 bytes to the right of 320-byte region [0x6120000001c0,0x612000000300)
allocated by thread T0 here:
    #0 0x7f48284c2448 in malloc (/lib/x86_64-linux-gnu/libasan.so.5+0x10c448)
    #1 0x561b936b2232 in opj_j2k_read_siz Source/LibOpenJPEG/j2k.c:2193
    #2 0x561b936c7a58 in opj_j2k_read_header_procedure Source/LibOpenJPEG/j2k.c:6980
    #3 0x561b936ad050 in opj_j2k_exec Source/LibOpenJPEG/j2k.c:7035
    #4 0x561b936c9cbc in opj_j2k_read_header Source/LibOpenJPEG/j2k.c:6567
    #5 0x561b92a443dd in Load Source/FreeImage/PluginJ2K.cpp:169
    #6 0x561b929d147b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:388
    #7 0x561b929d147b in FreeImage_LoadFromHandle Source/FreeImage/Plugin.cpp:380
    #8 0x561b929d1952 in FreeImage_Load Source/FreeImage/Plugin.cpp:408
    #9 0x561b9298c12b in main /home/lab4/src/freeimage-svn/FreeImage/trunk/load-test.c:16

SUMMARY: AddressSanitizer: heap-buffer-overflow Source/LibOpenJPEG/j2k.c:7110 in opj_j2k_copy_default_tcp_and_create_tcd
Shadow bytes around the buggy address:
  0x0c247fff8010: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c247fff8020: 00 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa
  0x0c247fff8030: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c247fff8040: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c247fff8050: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c247fff8060: fa fa[fa]fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c247fff8070: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c247fff8080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c247fff8090: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x0c247fff80a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c247fff80b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
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
==23845==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_j2k_7110

Credit

ADLab of Venustech

1 Attachments

Discussion


Log in to post a comment.

MongoDB Logo MongoDB