Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Tests/test_file_fpx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from io import BytesIO

import pytest

from PIL import Image
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/PIL/FpxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading