Skip to content

Commit fccc261

Browse files
authored
Merge pull request #5899 from radarhere/bmp
Ensure that BMP pixel data offset does not ignore palette
2 parents 17ec8b5 + ff723e4 commit fccc261

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Tests/images/pal8_offset.bmp

9.04 KB
Binary file not shown.

Tests/test_file_bmp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,10 @@ def test_rgba_bitfields():
123123
im = Image.merge("RGB", (r, g, b))
124124

125125
assert_image_equal_tofile(im, "Tests/images/bmp/q/rgb32bf-xbgr.bmp")
126+
127+
128+
def test_offset():
129+
# This image has been hexedited
130+
# to exclude the palette size from the pixel data offset
131+
with Image.open("Tests/images/pal8_offset.bmp") as im:
132+
assert_image_equal_tofile(im, "Tests/images/bmp/g/pal8.bmp")

src/PIL/BmpImagePlugin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ def _bitmap(self, header=0, offset=0):
158158
if file_info.get("colors", 0)
159159
else (1 << file_info["bits"])
160160
)
161+
if offset == 14 + file_info["header_size"] and file_info["bits"] <= 8:
162+
offset += 4 * file_info["colors"]
161163

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

0 commit comments

Comments
 (0)