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

Integer Overflow at t2.c:1234 #1488

Closed
wants to merge 1 commit into from
Closed

Conversation

headshog
Copy link
Contributor

@headshog headshog commented Dec 6, 2023

Hi! We've been fuzzing openjpeg with sydr-fuzz security predicates and we found integer overflow error in t2.c:1234.

In function opj_t2_read_packet_header at line 1234 integer overflow occurs (in our case it was l_band->numbps = 5 and i = 15, so 5+1-15 in case of OPJ_UINT32 gives overflow) and nowhere else in this function validity of this variable is checked. So i tried to put a checker there similarly to other return OPJ_FALSE branches in this function.

Environment

How to reproduce this error

  1. Build docker container:

    sudo docker build -t oss-sydr-fuzz-openjpeg .
    
    
  2. Run docker container:

    sudo docker run --privileged --network host -v /etc/localtime:/etc/localtime:ro --rm -it -v $PWD:/fuzz oss-sydr-fuzz-openjpeg /bin/bash
    
    
  3. Run on the following input:

     /opj_decompress_fuzzer_JP2_fuzz sydr_t2.txt
    
    
  4. Output:

    /openjpeg/src/lib/openjp2/t2.c:1234:65: runtime error: unsigned integer overflow: 6 - 15 cannot be represented in type 'unsigned int'
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /openjpeg/src/lib/openjp2/t2.c:1234:65
    

@rouault
Copy link
Collaborator

rouault commented Dec 8, 2023

That change cause additional test failures:
43 - ETS-C1P0-p0_06.j2k-compare2ref (Failed)
44 - NR-C1P0-p0_06.j2k-compare2base (Failed)

Would require deeper analysis to see if they are legit

@rouault
Copy link
Collaborator

rouault commented Feb 18, 2024

alternate fix in #1511

@rouault rouault closed this Feb 18, 2024
rouault added a commit to rouault/openjpeg that referenced this pull request Feb 18, 2024
clrpackages pushed a commit to clearlinux-pkgs/openjpeg that referenced this pull request May 3, 2024
…2.5.2

Aleks L (1):
      Fix Heap-buffer-overflow READ in opj_jp2_apply_pclr (#1441)

Alex Richardson (1):
      Make OpenJPEGConfig.cmake relocatable with CMake > 3.0

Alexander Neumann (1):
      Fix windows arm builds

Andrew Murray (1):
      Fixed typos (#1486)

Aous Naman (1):
      Replace the assert in mel_init to an if statement to address an issue with fuzzing. (#1436)

Biswapriyo Nath (1):
      pkgconfig: Define OPJ_STATIC for static linking with pkgconf

Dominik Wójt (2):
      CMake: drop support for cmake < 3.5
      Add cmake version file

Even Rouault (29):
      abi_check.sh: Update version number for automatic abi check
      update tools/abi-tracker/openjpeg.json
      abi_check.sh: comment OPJ_PREVIOUS_VERSION
      HOWTO-RELEASE: update
      Build: fix linking of executables on some systems where TIFF/LCMS2 static libraries are not in system directories (fixes #1430)
      opj_t1_encode_cblk(): avoid undefined behaviour on fuzzed input (fixes #1432)
      Micro-optimization: use directly opj_bio_putbit() instead of opj_bio_write() to emit single bit
      Significant speed-up rate allocation by rate/distoratio ratio
      Cleanup code related to quality layer allocation, and add a few safety checks
      Fix incorrect decoding of image with large number of progression levels
      opj_t2_skip_packet_data(): avoid out-of-bounds reads on truncated images in non-strict mode (fixes #1459)
      Fix CI
      Remove support for non-C99 compilers (like VS2010) that don't support snprintf()
      opj_jp2_read_header(): move setting color_space here instead in opj_jp2_decode()/get_tile() (fixes #570)
      opj_jp2_read_header(): move setting icc_profile here instead in opj_jp2_decode()/get_tile() + add unit test (fixes #570)
      CI: update KDU to new version (older one no longer available)
      tools/travis-ci/install.sh: workaround issue with jpylyzer on Mac
      opj_tcd_dc_level_shift_decode(): avoid increment nullptr (fixes #1480)
      opj_decompress: fix off-by-one read heap-buffer-overflow in sycc420_to_rgb() when x0 and y0 are odd (CVE-2021-3575, fixes #1347)
      opj_dwt_decode_tile(): avoid potential UndefinedBehaviorSanitizer 'applying zero offset to null pointer' (fixes #1505)
      opj_t2_read_packet_header(): avoid unsigned integer overflow (alternate fix to uclouvain/openjpeg#1488)
      Prepare for OpenJPEG v2.5.1 release
      abi_check.sh: Update version number for automatic abi check (2.5.0->2.5.1)
      abi_check.sh: comment OPJ_PREVIOUS_VERSION
      update HOWTO-RELEASE
      update HOWTO-RELEASE
      openjpeg.h: make sure to include opj_config.h (fixes #1514)
      opj_config.h.cmake.in: add inclusion guard
      Prepare for OpenJPEG v2.5.2 release

Mark Mentovai (1):
      openjp2/j2k: replace sprintf calls with snprintf

Miloš Komarčević (2):
      Always install pkgconfig files
      Remove BUILD_PKGCONFIG_FILES

Peter Johnson (1):
      ht_dec.c: Improve MSVC arm64 popcount performance (#1479)

Sebastian Rasmussen (1):
      CMake: error out on warnings for strict/missing prototypes.

Thomas Bracht Laumann Jespersen (1):
      CMake: switch to GNUInstallDirs  (#1424)

Tomoaki Teshima (1):
      suppress warning during build using clang

Yuan (1):
      HT_DEC: Fix opj_t1_allocate_buffers malloc size error (#1426) (fixes #1413)

autoantwort (1):
      CMake: add missing GNUInstallDirs related substitutions (fixes #1424) (#1456)

headshog (3):
      opj_j2k_merge_ppm(): avoid unsigned-integer-overflow at j2k.c:3962 (#1490)
      fix j2k.c:11114
      opj_t1_ht_decode_cblk(): avoid memcpy() with 0-input size and nullptr destination. fix ht_dec.c:1215 (#1492)

mayeut (3):
      fix: use `opj_uint_ceildiv` instead of `opj_int_ceildiv` when necessary
      chore: GHA Ubuntu 22.04 now uses gcc 11.4.0
      Require `stdint.h` & `inttypes.h`

scaramallion (1):
      Fix compiler error on Windows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants