Treat an MPO with too few MP entries as a JPEG#9826
Merged
radarhere merged 2 commits intoJul 27, 2026
Conversation
radarhere
reviewed
Jul 26, 2026
radarhere
approved these changes
Jul 26, 2026
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.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.
jpeg_factory()deliberately falls back to a plain JPEG when the MP index cannot be read. It catchesTypeErrorandIndexError, and warns forSyntaxError, which is whattest_bad_mpo_headercovers. One case in_getmp()escapes that:struct.error.The MP index stores the number of images (
0xB001) and the MP entries (0xB002) separately, and nothing checks that they agree. If the number of images is larger than the number of entries actually present,struct.unpack_from()reads off the end of the entry buffer:struct.erroris not caught injpeg_factory(), so it reaches_open_core(), which treats it as "this plugin cannot open the file". JPEG is the only format that accepts the prefix, so the whole image becomes unopenable even though the JPEG data itself is fine.Removing the MP entry tag instead raises
KeyErrorinside_getmp(), which is already turned intoSyntaxError("malformed MP Index (bad MP Entry)"), and that file opens as a JPEG with a warning. A short entry buffer means the same thing, so this raises the same error for it.Changes proposed in this pull request:
SyntaxErrorinstead of lettingstruct.errorescape_getmp()when the MP index declares more images than it has entriestest_bad_mpo_header