Skip to content

Commit b2945ec

Browse files
committed
Test truncated header
1 parent dce9608 commit b2945ec

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

Tests/test_file_xpm.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,22 @@ def test_rgb() -> None:
3333
assert_image_similar(im, hopper(), 16)
3434

3535

36-
def test_cannot_read() -> None:
36+
def test_truncated_header() -> None:
37+
data = b"/* XPM */"
38+
with pytest.raises(SyntaxError, match="broken XPM file"):
39+
with XpmImagePlugin.XpmImageFile(BytesIO(data)):
40+
pass
41+
42+
43+
def test_cannot_read_color() -> None:
3744
with open(TEST_FILE, "rb") as fp:
3845
data = fp.read().split(b"#")[0]
3946
with pytest.raises(ValueError, match="cannot read this XPM file"):
40-
with Image.open(BytesIO(data)) as im:
47+
with Image.open(BytesIO(data)):
4148
pass
49+
4250
with pytest.raises(ValueError, match="cannot read this XPM file"):
43-
with Image.open(BytesIO(data+b"invalid")) as im:
51+
with Image.open(BytesIO(data + b"invalid")):
4452
pass
4553

4654

0 commit comments

Comments
 (0)