From c0b5d013f6e3313456848f3969231e7ee3ee6031 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 4 Mar 2025 22:19:06 +1100 Subject: [PATCH] Test bad image size and unknown PCX mode --- Tests/test_file_pcx.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tests/test_file_pcx.py b/Tests/test_file_pcx.py index b3f38c3e5..aa24189f4 100644 --- a/Tests/test_file_pcx.py +++ b/Tests/test_file_pcx.py @@ -1,5 +1,6 @@ from __future__ import annotations +import io from pathlib import Path import pytest @@ -36,6 +37,28 @@ def test_sanity(tmp_path: Path) -> None: im.save(f) +def test_bad_image_size() -> None: + with open("Tests/images/pil184.pcx", "rb") as fp: + data = fp.read() + data = data[:4] + b"\xff\xff" + data[6:] + + b = io.BytesIO(data) + with pytest.raises(SyntaxError, match="bad PCX image size"): + with PcxImagePlugin.PcxImageFile(b): + pass + + +def test_unknown_mode() -> None: + with open("Tests/images/pil184.pcx", "rb") as fp: + data = fp.read() + data = data[:3] + b"\xff" + data[4:] + + b = io.BytesIO(data) + with pytest.raises(OSError, match="unknown PCX mode"): + with Image.open(b): + pass + + def test_invalid_file() -> None: invalid_file = "Tests/images/flower.jpg"