Skip to content

Fix HTJ2K bytes-per-line integer overflow in internal_ht.cpp#2342

Closed
cary-ilm wants to merge 1 commit intoAcademySoftwareFoundation:mainfrom
cary-ilm:ht-overflow-fix
Closed

Fix HTJ2K bytes-per-line integer overflow in internal_ht.cpp#2342
cary-ilm wants to merge 1 commit intoAcademySoftwareFoundation:mainfrom
cary-ilm:ht-overflow-fix

Conversation

@cary-ilm
Copy link
Copy Markdown
Member

@cary-ilm cary-ilm commented Apr 8, 2026

Accumulate bpl in int64_t with int64 per-channel products, reject sums above INT_MAX with EXR_ERR_CORRUPT_CHUNK (mirrors PIZ wcount*nx guard). Harden raster_line_offset summation with uint64_t. Apply the same bpl logic to ht_apply_impl. Use ptrdiff_t for non-planar line strides after validation.

Addresses CVE-2026-39886

Made-with: Cursor

Accumulate bpl in `int64_t` with `int64` per-channel products, reject sums
above `INT_MAX` with `EXR_ERR_CORRUPT_CHUNK` (mirrors PIZ `wcount*nx` guard).
Harden `raster_line_offset` summation with `uint64_t`. Apply the same `bpl`
logic to `ht_apply_impl`. Use `ptrdiff_t `for non-planar line strides after
validation.

Made-with: Cursor
Signed-off-by: Cary Phillips <cary@ilm.com>
@cary-ilm cary-ilm requested a review from kdt3rd April 8, 2026 00:57
{
int32_t w = decode->channels[i].width;
int8_t bpe = decode->channels[i].bytes_per_element;
if (w < 0 || bpe < 0) return EXR_ERR_CORRUPT_CHUNK;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

w and bpe are the responsibility of the caller, shouldn't the check happen there?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true that width and bytes_per_element should have valid values before entry, but the test here still seems worthwhile before a cast that would fail if they're invalid. It's a simply test, I'd vote for leaving it in place.

Do you understand the code path well enough to understand exactly where that validation should happen if not here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cary-ilm
Copy link
Copy Markdown
Member Author

closing in favor of #2345

@cary-ilm cary-ilm closed this Apr 10, 2026
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