Skip to content
Merged
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
12 changes: 11 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,15 @@ def test_invalid_file() -> None:
FpxImagePlugin.FpxImageFile(ole_file)


def test_fpx_invalid_number_of_bands() -> None:
def test_invalid_tile_size() -> None:
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ValueError seems the right choice, although we're already raising OSError for other things which should probably be ValueError (if we were writing from scratch).

Maybe use OSError here for consistency? Or ValueError for any new ones? I don't mind too much either way.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could go either way. I'm more inclined towards what is theoretically correct.


# channels = i32(s, 24)
offset = i32(s, 28)
length = i32(s, 32)
Expand Down
Loading