Skip to content

Commit c23bf05

Browse files
authored
Merge pull request #8797 from radarhere/pcx
Improved PcxImagePlugin test coverage
2 parents ebdfca3 + c0b5d01 commit c23bf05

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Tests/test_file_pcx.py

+23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import io
34
from pathlib import Path
45

56
import pytest
@@ -36,6 +37,28 @@ def test_sanity(tmp_path: Path) -> None:
3637
im.save(f)
3738

3839

40+
def test_bad_image_size() -> None:
41+
with open("Tests/images/pil184.pcx", "rb") as fp:
42+
data = fp.read()
43+
data = data[:4] + b"\xff\xff" + data[6:]
44+
45+
b = io.BytesIO(data)
46+
with pytest.raises(SyntaxError, match="bad PCX image size"):
47+
with PcxImagePlugin.PcxImageFile(b):
48+
pass
49+
50+
51+
def test_unknown_mode() -> None:
52+
with open("Tests/images/pil184.pcx", "rb") as fp:
53+
data = fp.read()
54+
data = data[:3] + b"\xff" + data[4:]
55+
56+
b = io.BytesIO(data)
57+
with pytest.raises(OSError, match="unknown PCX mode"):
58+
with Image.open(b):
59+
pass
60+
61+
3962
def test_invalid_file() -> None:
4063
invalid_file = "Tests/images/flower.jpg"
4164

0 commit comments

Comments
 (0)