Skip to content

Raise error if declared JPEG2000 marker length is too small#9666

Merged
radarhere merged 1 commit into
python-pillow:mainfrom
radarhere:jpeg2k_marker_length
Jun 9, 2026
Merged

Raise error if declared JPEG2000 marker length is too small#9666
radarhere merged 1 commit into
python-pillow:mainfrom
radarhere:jpeg2k_marker_length

Conversation

@radarhere

Copy link
Copy Markdown
Member

In two places in Jpeg2KImagePlugin, it is possible for file data to be such that Pillow calls read() with a negative number.

lsiz = _binary.i16be(hdr)
siz = hdr + fp.read(lsiz - 2)

hdr = self.fp.read(2)
length = _binary.i16be(hdr)
if typ == 0x64:
# Comment
self.info["comment"] = self.fp.read(length - 2)[2:]

This would unintentionally read the rest of the file. This PR changes those places to raise an error instead.

@radarhere radarhere added the JPEG label Jun 9, 2026
@radarhere radarhere merged commit 701d404 into python-pillow:main Jun 9, 2026
60 of 61 checks passed
@radarhere radarhere deleted the jpeg2k_marker_length branch June 9, 2026 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants