diff --git a/Tests/images/pal8_offset.bmp b/Tests/images/pal8_offset.bmp new file mode 100644 index 00000000000..24be65f22c3 Binary files /dev/null and b/Tests/images/pal8_offset.bmp differ diff --git a/Tests/test_file_bmp.py b/Tests/test_file_bmp.py index 3374fe54e94..47fc97df055 100644 --- a/Tests/test_file_bmp.py +++ b/Tests/test_file_bmp.py @@ -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") diff --git a/src/PIL/BmpImagePlugin.py b/src/PIL/BmpImagePlugin.py index 7bfe733e52d..7a7ad386c6f 100644 --- a/src/PIL/BmpImagePlugin.py +++ b/src/PIL/BmpImagePlugin.py @@ -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))