From b2945ec2aaf20d4698479c843f0d26ffcaf6222b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 10 Apr 2025 22:07:55 +1000 Subject: [PATCH] Test truncated header --- Tests/test_file_xpm.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Tests/test_file_xpm.py b/Tests/test_file_xpm.py index de2d9bb79..86d86602f 100644 --- a/Tests/test_file_xpm.py +++ b/Tests/test_file_xpm.py @@ -33,14 +33,22 @@ def test_rgb() -> None: assert_image_similar(im, hopper(), 16) -def test_cannot_read() -> None: +def test_truncated_header() -> None: + data = b"/* XPM */" + with pytest.raises(SyntaxError, match="broken XPM file"): + with XpmImagePlugin.XpmImageFile(BytesIO(data)): + pass + + +def test_cannot_read_color() -> None: with open(TEST_FILE, "rb") as fp: data = fp.read().split(b"#")[0] with pytest.raises(ValueError, match="cannot read this XPM file"): - with Image.open(BytesIO(data)) as im: + with Image.open(BytesIO(data)): pass + with pytest.raises(ValueError, match="cannot read this XPM file"): - with Image.open(BytesIO(data+b"invalid")) as im: + with Image.open(BytesIO(data + b"invalid")): pass