Skip to content

Align RLE absolute runs on the run length, not the file position - #10715

Open
rome-xi wants to merge 2 commits into
python-pillow:mainfrom
rome-xi:fix/10713-bmp-rle-absolute-align
Open

rome-xi wants to merge 2 commits into
python-pillow:mainfrom
rome-xi:fix/10713-bmp-rle-absolute-align

Conversation

@rome-xi

@rome-xi rome-xi commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #10713.

BMP absolute-mode RLE runs must be padded to a 16-bit word boundary based on the length of the run. The decoder used fd.tell() % 2, which is wrong when the pixel data starts at an odd offset (the header can skip unused bytes). After an odd-length absolute run the pad byte was not skipped, so the following codes were decoded one byte off.

This pads using byte_count % 2 instead. Tests/test_file_bmp.py::test_rle8_absolute_word_align covers even and odd pixel-data offsets.

@radarhere radarhere added the BMP label Dec 4, 2026
@bactiar291

Copy link
Copy Markdown

Independent local verification against this PR's exact base (ed0ca1c4) and head (252267f1) on Python 3.14.9:

  • RLE8 5×1 reproduction with data gaps 0/1: base 1 passed, 1 failed (gap=1 decoded [1, 2, 3, 0, 0]); PR head 2 passed.
  • Tests/test_file_bmp.py on the PR head: 39 passed.
  • I also exercised an analogous RLE4 stream through the shared branch: the odd-offset case fails on base and both offsets pass on this head. Would you consider adding that adjacent RLE4 regression case too?

Disclosure: AI-assisted validation and comment.

Absolute-mode padding is based on the run's byte count, not the file
position. Cover the shared RLE4 path the same way as RLE8, including
an odd data offset that previously consumed the next command as pad.
@rome-xi

rome-xi commented Dec 4, 2026

Copy link
Copy Markdown
Author

Thanks @bactiar291 — good catch. I added test_rle4_absolute_word_align for even and odd data offsets on the shared decoder path. On this PR's base, the odd-offset case fails the same way as RLE8 ([1, 2, 3, 0, 0] instead of [1, 2, 3, 2, 2]); both offsets pass on this head, and Tests/test_file_bmp.py is 41 passing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BMP RLE absolute runs are aligned on the file position, so pixel data at an odd offset is decoded wrongly

3 participants