From d7a8312beb6433c94f338cb9412847455006a86e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 5 Jun 2026 23:26:00 +1000 Subject: [PATCH] Raise ValueError if tile size is not 64px by 64px --- Tests/test_file_fpx.py | 13 ++++++++++++- src/PIL/FpxImagePlugin.py | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_fpx.py b/Tests/test_file_fpx.py index 8d8064692e5..4ff33bddf67 100644 --- a/Tests/test_file_fpx.py +++ b/Tests/test_file_fpx.py @@ -1,5 +1,7 @@ from __future__ import annotations +from io import BytesIO + import pytest from PIL import Image @@ -43,7 +45,16 @@ def test_invalid_file() -> None: FpxImagePlugin.FpxImageFile(ole_file) -def test_fpx_invalid_number_of_bands() -> None: +def test_invalid_size() -> None: + # Test a valid OLE file, but not an FPX file + with open("Tests/images/input_bw_one_band.fpx", "rb") as f: + data = f.read() + data = data[:4204] + b"\x00" * 8 + data[4212:] + with pytest.raises(ValueError, match="Tile must be 64 pixels by 64 pixels"): + Image.open(BytesIO(data)) + + +def test_invalid_number_of_bands() -> None: with pytest.raises(OSError, match="Invalid number of bands"): with Image.open("Tests/images/input_bw_five_bands.fpx"): pass diff --git a/src/PIL/FpxImagePlugin.py b/src/PIL/FpxImagePlugin.py index 0b06aac965f..f7eafe4d5e7 100644 --- a/src/PIL/FpxImagePlugin.py +++ b/src/PIL/FpxImagePlugin.py @@ -142,6 +142,10 @@ def _open_subimage(self, index: int = 1, subimage: int = 0) -> None: size = i32(s, 4), i32(s, 8) # tilecount = i32(s, 12) xtile, ytile = i32(s, 16), i32(s, 20) + if xtile != 64 or ytile != 64: + msg = "Tile must be 64 pixels by 64 pixels" + raise ValueError(msg) + # channels = i32(s, 24) offset = i32(s, 28) length = i32(s, 32)