Ensure that pixel data offset does not ignore palette

This commit is contained in:
Andrew Murray 2021-12-21 12:43:50 +11:00
parent 591e79e01e
commit ff723e45ab
3 changed files with 9 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

@ -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")

View File

@ -158,6 +158,8 @@ class BmpImageFile(ImageFile.ImageFile):
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))