Fix negative-count memcpy in EXR decoder#216
Merged
eustas merged 2 commits intogoogle:mainfrom May 8, 2026
Merged
Conversation
eustas
approved these changes
May 6, 2026
Collaborator
|
Please rebase. Please consider submitting similar PR for libjxl. |
In DecodeImageEXR, when the EXR data window and display window have no horizontal overlap, exr_x2 < exr_x1, so (exr_x2 - exr_x1 + 1) wraps to a huge size_t and produces an out-of-bounds memcpy. Hoist exr_x1 and exr_x2 above the exr_y loop (they don't depend on the y-iteration), compute exr_x_span = max(0, exr_x2 - exr_x1 + 1), and skip the entire y-loop when exr_x_span is zero.
7b8b9f4 to
9222fd3
Compare
2 tasks
Contributor
Author
|
Done on both counts.
|
eustas
approved these changes
May 8, 2026
sharadboni
added a commit
to sharadboni/jpegli
that referenced
this pull request
May 8, 2026
In DecodeImageEXR, the OpenEXR framebuffer base pointer for extra
channels was computed using extraPixelBytes (sum of all extra
channels' per-pixel sizes), but each per-channel Slice was configured
with the channel's individual size. With dataWindow.min.x > 0 (or
start_y > 0) and multiple extra channels, OpenEXR's pixel address
resolution
base + x * size + y * size * row_size
underflows the input_extra_rows allocation by
data_min_x * (extraPixelBytes - size) bytes for channel 0's first
pixel, and a similar term for higher chunks. The result is a
heap-buffer-underflow write of attacker-controlled bytes (the EXR
extra-channel pixel data) at a controllable offset before the
allocated buffer.
Fix: keep input_extra_rows.data() unmodified as the per-channel
section base, and compute a separate ch_base_ptr per channel using
that channel's own size. With this, each channel's slice resolves
addresses correctly within its own section.
The negative-count memcpy at exr.cc:365 (also originally addressed
by this branch) was merged separately via google#216 and is unaffected by
this change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Security fix
Negative-count memcpy in EXR decoder (
lib/extras/dec/exr.cc)In
DecodeImageEXR, when the EXR data window and display window have no horizontal overlap, the intersection producesexr_x2 < exr_x1(afterstd::max/std::min). The expression(exr_x2 - exr_x1 + 1)then wraps to a hugesize_tand is passed tomemcpy, causing a massive out-of-bounds read/write.Refactor (per maintainer review on #213)
exr_x1andexr_x2above theexr_yloop — they don't depend onexr_y.exr_x_span = max(0, exr_x2 - exr_x1 + 1).exr_yloop whenexr_x_span == 0(no overlap → no work to do).exr_x_spandirectly in bothmemcpycalls (color + extra channels).This was originally bundled with an unrelated jpegli encoder fix in #213; split out per maintainer request since this fix is also useful for JPEG XL.