Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heap-buffer-overflow in opj_j2k_tcp_destroy #430

Closed
gcode-importer opened this issue Nov 14, 2014 · 12 comments
Closed

Heap-buffer-overflow in opj_j2k_tcp_destroy #430

gcode-importer opened this issue Nov 14, 2014 · 12 comments

Comments

@gcode-importer
Copy link

Originally reported on Google Code with ID 430

https://code.google.com/p/chromium/issues/detail?id=430891

Issue reproduced on trunk r2924 using MacOs x64 ASan build :
./bin/opj_decompress -i ../../ex/0.jp2 -o 0.bmp

[INFO] Start to read j2k main header (28).
[ERROR] We expected read a marker ID (0xff--) instead of 00006767
ERROR -> opj_decompress: failed to read the header
=================================================================
==3031==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x61200000be90 at
pc 0x000108ece5fe bp 0x7fff57c495c0 sp 0x7fff57c495b8
READ of size 8 at 0x61200000be90 thread T0
    #0 0x108ece5fd in opj_j2k_tcp_destroy /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/j2k.c:7584:29
    #1 0x108ec7c12 in opj_j2k_destroy /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/j2k.c:7453:25
    #2 0x108eeffcb in opj_jp2_destroy /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/jp2.c:2602:3
    #3 0x108ef6c74 in opj_destroy_codec /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/openjpeg.c:851:4
    #4 0x107fb7e46 in main /Users/Matt/Dev/OpenJpeg/issue/src/bin/jp2/opj_decompress.c:804:4
    #5 0x7fff8f0735c8 in start (/usr/lib/system/libdyld.dylib+0x35c8)
    #6 0x4 (<unknown module>)

0x61200000be90 is located 16 bytes to the right of 320-byte region [0x61200000bd40,0x61200000be80)
allocated by thread T0 here:
    #0 0x108213193 in wrap_calloc (/Users/Matt/Dev/llvm-clang-3.5.0-macosx-apple-darwin/lib/clang/3.5.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib+0x2c193)
    #1 0x108ec2b9f in opj_j2k_read_siz /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/j2k.c:2202:42
    #2 0x108ee4cae in opj_j2k_read_header_procedure /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/j2k.c:7226:23
    #3 0x108ecddaa in opj_j2k_exec /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/j2k.c:7294:41
    #4 0x108ecdb17 in opj_j2k_read_header /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/j2k.c:6788:15
    #5 0x107fb7745 in main /Users/Matt/Dev/OpenJpeg/issue/src/bin/jp2/opj_decompress.c:801:8
    #6 0x7fff8f0735c8 in start (/usr/lib/system/libdyld.dylib+0x35c8)
    #7 0x4 (<unknown module>)

SUMMARY: AddressSanitizer: heap-buffer-overflow /Users/Matt/Dev/OpenJpeg/issue/src/lib/openjp2/j2k.c:7584
opj_j2k_tcp_destroy
Shadow bytes around the buggy address:
  0x1c2400001780: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x1c2400001790: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x1c24000017a0: fa fa fa fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x1c24000017b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c24000017c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x1c24000017d0: fa fa[fa]fa fa fa fa fa 00 00 00 00 00 00 00 00
  0x1c24000017e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  0x1c24000017f0: 00 00 00 00 00 00 00 00 00 00 00 00 fa fa fa fa
  0x1c2400001800: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c2400001810: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x1c2400001820: 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
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  ASan internal:           fe
==3031==ABORTING

Reported by mayeut on 2014-11-14 19:37:51

@gcode-importer
Copy link
Author

Reported by mayeut on 2014-11-14 19:38:21


- _Attachment: [issue430.jp2](https://storage.googleapis.com/google-code-attachments/openjpeg/issue-430/comment-1/issue430.jp2)_

@gcode-importer
Copy link
Author

@antonin,

The patch corrects the ASan issue however, I don't have ISO 15444-2 at hand so I cannot
check what I've done & test suite coverage does not include opj_j2k_read_mct... 

Reported by mayeut on 2014-11-21 20:26:03


- _Attachment: [issue430.patch](https://storage.googleapis.com/google-code-attachments/openjpeg/issue-430/comment-2/issue430.patch)_

@gcode-importer
Copy link
Author

Reported by mayeut on 2014-11-22 00:11:25

  • Status changed: Started

@gcode-importer
Copy link
Author

Any update on this issue? Thanks!

Reported by bo_xu@foxitsoftware.com on 2014-12-20 00:49:39

@gcode-importer
Copy link
Author

$ kdu_expand.exe -i issue430.jp2 -o issue430.jp2_kdu.tif
Kakadu Core Error:
Code-stream must start with an SOC marker!

Problem does not seem to be at MCT level. Code-stream should be rejected earlier

Reported by detonin on 2015-01-20 11:26:57

@gcode-importer
Copy link
Author

JP2 file format that encapsulates the J2K code-stream is malformed. A check should be
added in OPJ to gracefully return when such situation occurs.

Attached is the raw J2K code-stream (without JP2 boxes) that has indeed (at least)
a malformed MCT marker.

$ kdu_expand.exe -i issue430.j2k -o issue430.j2k_kdu.tif
Kakadu Core Error:
Malformed MCT marker segment encountered. The final 1 bytes were not consumed!


Reported by detonin on 2015-01-20 12:40:41


- _Attachment: [issue430.j2k](https://storage.googleapis.com/google-code-attachments/openjpeg/issue-430/comment-6/issue430.j2k)_

@gcode-importer
Copy link
Author

This issue was updated by revision r2992.

Reported by detonin on 2015-01-20 14:27:28

@gcode-importer
Copy link
Author

This issue was updated by revision r2993.

@Mickael: this revision affects your work on custom MCT. Is there a way
you could provide test data to add to our test suite ? Thanks

Reported by detonin on 2015-01-20 16:29:31

@gcode-importer
Copy link
Author

@matthieu: could you check with ASan that issue is fixed ? Thanks

Reported by detonin on 2015-01-20 16:30:21

@gcode-importer
Copy link
Author

ASan reports no error at r2993 with both images (JP2/J2K)

Reported by mayeut on 2015-01-20 21:11:03

@gcode-importer
Copy link
Author

New issue 471 has been created to add test coverage for custom MCT.
This security issue is now fixed.
Thanks Matthieu and Bo.

Reported by detonin on 2015-01-21 16:27:19

  • Status changed: Fixed

@eslerm
Copy link

eslerm commented Sep 16, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants