fix(jpeg2000): guard the HTJ2K reader, not just the OpenJPEG one - #5407
Open
lgritz wants to merge 1 commit into
Open
fix(jpeg2000): guard the HTJ2K reader, not just the OpenJPEG one#5407lgritz wants to merge 1 commit into
lgritz wants to merge 1 commit into
Conversation
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>
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.
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