Repository navigation
Conversation
Stored scanlines are rounded up to 16 bits and the RLE stream encodes the padding bytes. The decoder advanced rows at the unpadded state->bytes, so a padding byte became the first pixel of the next row whenever a row's pixel data had an odd length. Advance rows on the padded stride, write only bytes that fall inside the row, and let runs cross scanlines while skipping padding. Add regression tests for literal rows and for a run crossing two padded rows.
This branch has not been deployed
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.
Fixes #10370.
What happens
Sun raster stored scanlines are rounded up to 16 bits, and type-2 RLE encodes the padding bytes too.
ImagingSunRleDecodeadvanced rows at the unpaddedstate->bytes, so whenever a row's pixel data had an odd length the padding byte was written as the first pixel of the next row:Fix
stride = state->bytes + (state->bytes & 1)and trackstate->xwithin the padded row.state->bufferonly whenx < state->bytes; the padding bytes are consumed but not stored.extra_bytesbookkeeping, which could not account for the padded stride.Tests
Added to
Tests/test_file_sun.py:test_rle_padded_row: a literal 3x2 8-bit image with one padding byte per row.test_rle_run_crosses_padded_rows: one run of 8 pixels covering two padded rows.python -m pytest Tests/test_file_sun.py -q→ 8 passed, 2 skipped (the skips need the extra image files, as before).I also checked the 24-bit
marbles.sunsample linked in the issue (1419 px wide): the installed Pillow 13.0.0 and this patch produce identical decoded pixel hashes, so the ImageMagick parity you verified is unchanged.Prepared with AI assistance; the patch and tests were reviewed and run locally.