Raise SyntaxError instead of OverflowError for oversized JPEG 2000 box#9818
Open
nevercodecorrect wants to merge 7 commits into
Open
Raise SyntaxError instead of OverflowError for oversized JPEG 2000 box#9818nevercodecorrect wants to merge 7 commits into
nevercodecorrect wants to merge 7 commits into
Conversation
radarhere
reviewed
Jul 23, 2026
Update payload to match the one in def _accept(prefix: bytes) -> bool: Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
Member
|
I've created nevercodecorrect#1 with a suggestion. |
Raise error when seeking, rather than when starting box
Author
|
Thank you. This actually makes more sense. I have applied it. |
radarhere
previously approved these changes
Jul 23, 2026
Consider new position, not just offset
Author
The previous guard only rejected an oversized box length on the seek path in next_box_type(). A box that is descended into via read_boxes() (e.g. the jp2h header box) still passed the huge length to BytesIO.read(), leaking OverflowError out of Image.open(). Move the check to the point where the length is stored, so it protects both consumers of remaining_in_box: the seek in next_box_type() and the read in read_boxes(). Add regression tests that independently trigger the seek path and the read path.
nevercodecorrect
force-pushed
the
jp2-oversized-box-length
branch
from
July 23, 2026 14:17
a1ead53 to
196974e
Compare
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.
Fixes #9817 .
JPEG 2000's BoxReader accepts an extended 64-bit box length with no bound (the top-level reader has no known length), then passes it to fp.seek(..., SEEK_CUR), raising OverflowError from Image.open() on malformed input.
This is the JP2 counterpart of #9811 (TIFF, fixed in #9816). The box is now rejected as a malformed header (SyntaxError → UnidentifiedImageError), consistent with the plugin's other #checks.
Changes proposed in this pull request: