Repository navigation
Handle unexpected EOF in JPEG header - #10150
Merged
radarhere merged 3 commits intoOct 10, 2026
Merged
Conversation
radarhere
force-pushed
the
fix/jpeg-marker-eof
branch
from
October 9, 2026 13:00
6a5a740 to
c11b9dc
Compare
radarhere
force-pushed
the
fix/jpeg-marker-eof
branch
from
October 10, 2026 04:25
c11b9dc to
808a983
Compare
Member
|
I've opted to exit the loop, instead of raising a specific error. I think this is more inline with how Pillow behaves, and still solves your problem. |
radarhere
enabled auto-merge (squash)
October 10, 2026 04:28
radarhere
approved these changes
Oct 10, 2026
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.
Seeking to an MPO frame whose offset points at data that isn't a JPEG stream crashes with an unhandled
IndexError:The marker scan in
JpegImageFile._openskips non-0xFF junk one byte at a time:If the file ends while skipping junk,
read(1)returnsb""and the next loop iteration doess[0]on empty bytes. When_openruns duringImage.open,ImageFilewraps that error, butMpoImageFile.seekcalls_opendirectly, so the rawIndexErrorescapes to the caller.This PR raises
SyntaxError("unexpected end of file")when the scan runs out of data, both in the junk-skip path and when EOF cuts a 0xFF marker in half (which otherwise failsi16with astruct.error).Reproducer:
Tests/images/mpo_junk_frame.mpo(added in this PR) is a normal two-frame MPO whose second-frame offset was hexedited to point at data that isn't a JPEG stream. On unpatched Pillow,im.seek(1)raisesIndexError; with this PR it raisesSyntaxError.Tests added:
test_mp_junk_frame_offsetinTests/test_file_mpo.pyandtest_eof_while_skipping_junkinTests/test_file_jpeg.py.