Skip to content

Replace boost::iterator_facade with explicit iterator definition for pcp/iterator.h#2328

Merged
pixar-oss merged 1 commit intoPixarAnimationStudios:devfrom
nvmkuruc:pcpiteratorfacade
Jul 27, 2023
Merged

Replace boost::iterator_facade with explicit iterator definition for pcp/iterator.h#2328
pixar-oss merged 1 commit intoPixarAnimationStudios:devfrom
nvmkuruc:pcpiteratorfacade

Conversation

@nvmkuruc
Copy link
Copy Markdown
Collaborator

@nvmkuruc nvmkuruc commented Mar 13, 2023

Description of Change(s)

Fixes Issue(s)

  • I have verified that all unit tests pass with the proposed changes
  • I have submitted a signed Contributor License Agreement

@nvmkuruc nvmkuruc changed the title Replace boost::iterator_facade with explicit iterator definition Replace boost::iterator_facade with explicit iterator definition for pcp/iterator.h Mar 13, 2023
@sunyab
Copy link
Copy Markdown
Contributor

sunyab commented Mar 14, 2023

Filed as internal issue #USD-8089

@nvmkuruc nvmkuruc force-pushed the pcpiteratorfacade branch from fa18738 to 9856497 Compare July 17, 2023 16:45
@pixar-oss pixar-oss merged commit 02f50cc into PixarAnimationStudios:dev Jul 27, 2023
@nvmkuruc nvmkuruc deleted the pcpiteratorfacade branch December 29, 2023 03:11
musicinmybrain pushed a commit to musicinmybrain/OpenUSD that referenced this pull request Apr 7, 2026
…Studios#2328)

Three classes of signed integer overflow in the PIZ codec path, all
reachable from corrupt `dataWindow` dimensions in the EXR file header.

**`wav_2D_encode` / `wav_2D_decode` — wavelet loop pointer arithmetic**

`oy` is passed as `int` (value `wcount * nx`, at most ~INT32_MAX after
the guard below). Inside the hierarchical wavelet loop the expressions

    ey  = in + oy * (ny - p2)   // pointer end-of-row sentinel
    oy1 = oy * p                // row stride at level p
    oy2 = oy * p2               // row stride at level p2

multiply two values that can each approach INT32_MAX, producing a
signed 32-bit product that wraps to a small or negative value. The
wrapped value is used as a pointer offset, causing reads and writes
through `px` / `py` to land outside the allocated wavelet buffer.

Fix: widen by introducing `int64_t oy64 = oy` and using it for all
three expressions; `oy1` and `oy2` are also declared `int64_t`.

**`wavbuf += nx * ny * wcount` — per-channel buffer advance**

`nx`, `ny`, and `wcount` are all `int`. Their triple product overflows
int32 for moderately large images, causing subsequent channels to be
processed at an incorrect (too-small) offset into the wavelet buffer,
corrupting both encode and decode output.

Fix: cast to `(uint64_t)` before multiplying.

**`wcount * nx` — call-site argument overflow**

The fifth argument to `wav_2D_encode` / `wav_2D_decode` is `wcount * nx`
(`oy` = y-stride = elements per row). `wcount` is 1 or 2
(`bytes_per_element / 2`); for `wcount = 2` the product overflows int32
when `nx > INT32_MAX / 2`.

Fix: add an early bounds check `if (wcount > 0 && nx > INT_MAX / wcount)`
that rejects such input as `EXR_ERR_CORRUPT_CHUNK` before any arithmetic
is performed. This also keeps `wcount * nx` within int32 range at the
call site, ensuring `oy` arrives in the wavelet functions with a valid
non-overflowed value.

Made-with: Cursor

Signed-off-by: Cary Phillips <cary@ilm.com>
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.

3 participants