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 Out-of-Bounds write in Imf_2_2::copyIntoFrameBuffer (72940266) #262

Closed
Google-Autofuzz opened this issue Feb 8, 2018 · 1 comment
Closed
Labels
Bug A bug in the source code

Comments

@Google-Autofuzz
Copy link

Hello OpenEXR team,

As part of our fuzzing efforts at Google, we have identified an issue affecting
OpenEXR (tested with revision * develop 165dcea).

To reproduce, we are attaching a Dockerfile which compiles the project with
LLVM, taking advantage of the sanitizers that it offers. More information about
how to use the attached Dockerfile can be found here:
https://docs.docker.com/engine/reference/builder/

TL;DR instructions:

  • mkdir project
  • cp Dockerfile.OpenEXR /path/to/project/Dockerfile
  • docker build --no-cache /path/to/project
  • docker run -it image_id_from_docker_build

From another terminal, outside the container:
docker cp /path/to/attached/reproducer running_container_hostname:/fuzzing/reproducer
(reference: https://docs.docker.com/engine/reference/commandline/cp/)

And, back inside the container:
/fuzzing/repro.sh /fuzzing/reproducer

Alternatively, and depending on the bug, you could use gcc, valgrind or other
instrumentation tools to aid in the investigation. The sanitizer error that we
encountered is here:

=================================================================
==21==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000ec50 at pc 0x00000053485d bp 0x7ffc2a3119e0 sp 0x7ffc2a3119d8
WRITE of size 2 at 0x60200000ec50 thread T0
    #0 0x53485c in half::operator=(half) /usr/local/include/OpenEXR/half.h:574:8
    #1 0x5b3e78 in Imf_2_2::copyIntoFrameBuffer(char const*&, char*, char*, unsigned long, bool, double, Imf_2_2::Compressor::Format, Imf_2_2::PixelType, Imf_2_2::PixelType) /fuzzing/openexr/OpenEXR/IlmImf/ImfMisc.cpp:317:40
    #2 0x672be3 in Imf_2_2::(anonymous namespace)::TileBufferTask::execute() /fuzzing/openexr/OpenEXR/IlmImf/ImfTiledInputFile.cpp:609:21
    #3 0x6bf8f4 in IlmThread_2_2::ThreadPool::addTask(IlmThread_2_2::Task*) /fuzzing/openexr/IlmBase/IlmThread/IlmThreadPool.cpp:433:15
    #4 0x66e709 in Imf_2_2::TiledInputFile::readTiles(int, int, int, int, int, int) /fuzzing/openexr/OpenEXR/IlmImf/ImfTiledInputFile.cpp:1204:21
    #5 0x66f230 in Imf_2_2::TiledInputFile::readTiles(int, int, int, int, int) /fuzzing/openexr/OpenEXR/IlmImf/ImfTiledInputFile.cpp:1260:5
    #6 0x633fb6 in Imf_2_2::(anonymous namespace)::bufferedReadPixels(Imf_2_2::InputFile::Data*, int, int) /fuzzing/openexr/OpenEXR/IlmImf/ImfInputFile.cpp:277:25
    #7 0x6339de in Imf_2_2::InputFile::readPixels(int, int) /fuzzing/openexr/OpenEXR/IlmImf/ImfInputFile.cpp:811:9
    #8 0x55de1f in Imf_2_2::RgbaInputFile::readPixels(int, int) /fuzzing/openexr/OpenEXR/IlmImf/ImfRgbaFile.cpp:1302:14
    #9 0x524a7a in (anonymous namespace)::readSingle(char const*) /fuzzing/security-research-pocs/autofuzz/openexr_fuzz_scanlines.cc:36:52
    #10 0x524805 in LLVMFuzzerTestOneInput /fuzzing/security-research-pocs/autofuzz/openexr_fuzz_scanlines.cc:113:3
    #11 0x516d9c in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/fuzzing/openexr_fuzz_scanlines+0x516d9c)
    #12 0x51655e in fuzzer::Fuzzer::RunOne(unsigned char const*, unsigned long) (/fuzzing/openexr_fuzz_scanlines+0x51655e)
    #13 0x5103bd in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*) (/fuzzing/openexr_fuzz_scanlines+0x5103bd)
    #14 0x51188f in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/fuzzing/openexr_fuzz_scanlines+0x51188f)
    #15 0x51026c in main (/fuzzing/openexr_fuzz_scanlines+0x51026c)
    #16 0x7f29e55cc2b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
    #17 0x425979 in _start (/fuzzing/openexr_fuzz_scanlines+0x425979)

0x60200000ec51 is located 0 bytes to the right of 1-byte region [0x60200000ec50,0x60200000ec51)
allocated by thread T0 here:
    #0 0x50d090 in operator new[](unsigned long) (/fuzzing/openexr_fuzz_scanlines+0x50d090)
    #1 0x632efd in Imf_2_2::InputFile::setFrameBuffer(Imf_2_2::FrameBuffer const&) /fuzzing/openexr/OpenEXR/IlmImf/ImfInputFile.cpp:713:14
    #2 0x55d849 in Imf_2_2::RgbaInputFile::setFrameBuffer(Imf_2_2::Rgba*, unsigned long, unsigned long) /fuzzing/openexr/OpenEXR/IlmImf/ImfRgbaFile.cpp:1269:14
    #3 0x524a25 in (anonymous namespace)::readSingle(char const*) /fuzzing/security-research-pocs/autofuzz/openexr_fuzz_scanlines.cc:34:9
    #4 0x524805 in LLVMFuzzerTestOneInput /fuzzing/security-research-pocs/autofuzz/openexr_fuzz_scanlines.cc:113:3
    #5 0x516d9c in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/fuzzing/openexr_fuzz_scanlines+0x516d9c)
    #6 0x51026c in main (/fuzzing/openexr_fuzz_scanlines+0x51026c)

SUMMARY: AddressSanitizer: heap-buffer-overflow /usr/local/include/OpenEXR/half.h:574:8 in half::operator=(half)
Shadow bytes around the buggy address:
  0x0c047fff9d30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9d40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9d50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9d60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9d70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa 01 fa
=>0x0c047fff9d80: fa fa 01 fa fa fa 01 fa fa fa[01]fa fa fa 00 fa
  0x0c047fff9d90: fa fa fd fa fa fa 01 fa fa fa 01 fa fa fa 04 fa
  0x0c047fff9da0: fa fa 04 fa fa fa 00 00 fa fa 00 00 fa fa 00 00
  0x0c047fff9db0: fa fa 00 00 fa fa 00 00 fa fa 04 fa fa fa fd fa
  0x0c047fff9dc0: fa fa 02 fa fa fa 00 fa fa fa fd fd fa fa fd fd
  0x0c047fff9dd0: fa fa fd fd fa fa fd fd fa fa fd fd fa fa 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
  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
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==21==ABORTING
INFO: Seed: 3481516057
/fuzzing/openexr_fuzz_deepscanlines: Running 1 inputs 1 time(s) each.
Running: /tmp/poc
Executed /tmp/poc in 1 ms

=================================================================
==25==ERROR: LeakSanitizer: detected memory leaks

We will gladly work with you so you can successfully confirm and reproduce this
issue. Do let us know if you have any feedback surrounding the documentation.

A possible patch for this issue has been attached for your consideration.

Once you have reproduced the issue, we'd appreciate to learn your expected
timeline for an update to be released. With any fix, please attribute the report
to "Google Autofuzz project".

We are also pleased to inform you that your project is eligible for inclusion to
the OSS-Fuzz project, which can provide additional continuous fuzzing, and
encourage you to investigate integration options.

Don't hesitate to let us know if you have any questions!

Google AutoFuzz Team
artifacts_72940266.zip
72940266.txt

@cary-ilm cary-ilm added the Bug A bug in the source code label Jun 13, 2019
peterhillman added a commit to peterhillman/openexr that referenced this issue Jul 11, 2019
peterhillman added a commit that referenced this issue Jul 12, 2019
@peterhillman
Copy link
Contributor

The suggested patch has now been tested and merged.
Thanks for the report and the patch!

DominicJacksonBFX pushed a commit to boris-fx/mocha-openexr that referenced this issue Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in the source code
Projects
None yet
Development

No branches or pull requests

3 participants