Skip to content

fix(jpeg2000): guard the HTJ2K reader, not just the OpenJPEG one - #5407

Open
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-htj2k
Open

fix(jpeg2000): guard the HTJ2K reader, not just the OpenJPEG one#5407
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-htj2k

Conversation

@lgritz

@lgritz lgritz commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

This plugin has two reader codepaths, one using OpenJPEG and the other using HTJ2K. Earlier bomb-header guards only covered the OpenJPEG path. The HTJ2K's open() function read width and height straight from the header and then allocated the full image before any check ran. The HTJ2K path now runs the same size checks as the OpenJPEG path before it sizes anything from the header.

Error handling on this path was also broken. A failed read logged an error but did not stop; the code kept going and used image data that was never filled in. This happened in two decode loops, and also when the codestream failed to open. One buffer resize sat outside its own error check. The read function could then return success after logging failure, so callers copied scanlines out of an empty buffer. Each of these paths now stops on error, and the scanline copy is bounds-checked.

Two more small fixes: a file with zero color components used to read past the end of an internal array, so that case is now rejected. And one error path in ICC strict mode used to skip closing the file; it now closes it like every other failure path.

Assisted-by: Claude Code / claude-opus-5

This plugin has two reader codepaths, one using OpenJPEG and the other
using HTJ2K. Earlier bomb-header guards only covered the OpenJPEG
path. The HTJ2K's open() function read width and height straight from
the header and then allocated the full image before any check ran.
The HTJ2K path now runs the same size checks as the OpenJPEG path
before it sizes anything from the header.

Error handling on this path was also broken. A failed read logged an
error but did not stop; the code kept going and used image data that
was never filled in. This happened in two decode loops, and also when
the codestream failed to open. One buffer resize sat outside its own
error check. The read function could then return success after logging
failure, so callers copied scanlines out of an empty buffer. Each of
these paths now stops on error, and the scanline copy is
bounds-checked.

Two more small fixes: a file with zero color components used to read
past the end of an internal array, so that case is now rejected. And
one error path in ICC strict mode used to skip closing the file; it
now closes it like every other failure path.

Assisted-by: Claude Code / claude-opus-5

Signed-off-by: Larry Gritz <lg@larrygritz.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.

1 participant