Skip to content

Commit

Permalink
Merge pull request #5899 from radarhere/bmp
Browse files Browse the repository at this point in the history
Ensure that BMP pixel data offset does not ignore palette
  • Loading branch information
hugovk committed Dec 28, 2021
2 parents 17ec8b5 + ff723e4 commit fccc261
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
Binary file added Tests/images/pal8_offset.bmp
Binary file not shown.
7 changes: 7 additions & 0 deletions Tests/test_file_bmp.py
Expand Up @@ -123,3 +123,10 @@ def test_rgba_bitfields():
im = Image.merge("RGB", (r, g, b))

assert_image_equal_tofile(im, "Tests/images/bmp/q/rgb32bf-xbgr.bmp")


def test_offset():
# This image has been hexedited
# to exclude the palette size from the pixel data offset
with Image.open("Tests/images/pal8_offset.bmp") as im:
assert_image_equal_tofile(im, "Tests/images/bmp/g/pal8.bmp")
2 changes: 2 additions & 0 deletions src/PIL/BmpImagePlugin.py
Expand Up @@ -158,6 +158,8 @@ def _bitmap(self, header=0, offset=0):
if file_info.get("colors", 0)
else (1 << file_info["bits"])
)
if offset == 14 + file_info["header_size"] and file_info["bits"] <= 8:
offset += 4 * file_info["colors"]

# ---------------------- Check bit depth for unusual unsupported values
self.mode, raw_mode = BIT2MODE.get(file_info["bits"], (None, None))
Expand Down

0 comments on commit fccc261

Please sign in to comment.