Skip to content

Commit c0b5d01

Browse files
committed
Test bad image size and unknown PCX mode
1 parent c7ed097 commit c0b5d01

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Tests/test_file_pcx.py

Lines changed: 23 additions & 0 deletions
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)