Skip to content

Commit 8e3784f

Browse files
authored
Test unsupported BMP bitfields layout (#9193)
2 parents 396755e + 2bf4822 commit 8e3784f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

Tests/test_file_bmp.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import pytest
77

88
from PIL import BmpImagePlugin, Image, _binary
9+
from PIL._binary import o16le as o16
10+
from PIL._binary import o32le as o32
911

1012
from .helper import (
1113
assert_image_equal,
@@ -114,7 +116,7 @@ def test_save_float_dpi(tmp_path: Path) -> None:
114116

115117

116118
def test_load_dib() -> None:
117-
# test for #1293, Imagegrab returning Unsupported Bitfields Format
119+
# test for #1293, ImageGrab returning Unsupported Bitfields Format
118120
with Image.open("Tests/images/clipboard.dib") as im:
119121
assert im.format == "DIB"
120122
assert im.get_format_mimetype() == "image/bmp"
@@ -219,6 +221,18 @@ def test_rle8_eof(file_name: str, length: int) -> None:
219221
im.load()
220222

221223

224+
def test_unsupported_bmp_bitfields_layout() -> None:
225+
fp = io.BytesIO(
226+
o32(40) # header size
227+
+ b"\x00" * 10
228+
+ o16(1) # bits
229+
+ o32(3) # BITFIELDS compression
230+
+ b"\x00" * 32
231+
)
232+
with pytest.raises(OSError, match="Unsupported BMP bitfields layout"):
233+
Image.open(fp)
234+
235+
222236
def test_offset() -> None:
223237
# This image has been hexedited
224238
# to exclude the palette size from the pixel data offset

0 commit comments

Comments
 (0)