Handle TGA images with packets that cross scan lines #6087
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.
Resolves #5729
https://en.wikipedia.org/wiki/Truevision_TGA
The image from the issue has these packets that crosses scan lines. I expect that we haven't dealt with this before because it is following an older specification. Currently, Pillow throws a buffer overrun error when handling this. At first, I was skeptical about removing a buffer overrun error, but then realised that it had been present since PIL, and #2241 removed the equivalent error for SUN images. The C changes here are modelled after #2241.
In other words, too much image data is found for a single row, and so this PR uses
extra_bytes
andextra_data
to store that, until it can be looped over later.The test image I have included was created by Pillow. Since Pillow plays it appropriately safe and does not cross scan lines, I then hexeditted it to test the relevant code.
Relevant documentation can be found at http://www.paulbourke.net/dataformats/tga/. Look at the "Image Data Field" under "DATA TYPE 10: Run Length Encoded, RGB images". The documentation also lead me to my first commit, to simplify reading two numbers from the file that are detailed the same way in the specification.