Handle multiple and malformed JPEG APP13 markers #4370
Merged
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 is a regression compared to Pillow 5.3, where the APP13 marker was not analyzing and images were opening without errors.
I met JPEGs with two APP13 markers were the first APP13 is always 65504 bytes length and looks like the second is just a continuation.
One of them: https://user-images.githubusercontent.com/128982/72672639-0a30b800-3a6e-11ea-88c2-d2b8fa8ca623.jpeg
This fix does not join markers since I don't know is it applicable for all files. Instead, it does not fail on the reading errors and collects data from all successfully processed markers.