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
10 changes: 10 additions & 0 deletions Tests/test_file_ftex.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,13 @@ def test_invalid_texture() -> None:
with pytest.raises(ValueError, match="Invalid texture compression format: 2"):
with Image.open(io.BytesIO(data)):
pass


def test_unsupported_texture_format_count() -> None:
with open("Tests/images/ftex_dxt1.ftc", "rb") as fp:
# Change the format count to an unsupported value
data = fp.read(20) + struct.pack("<i", 2)

with pytest.raises(ValueError, match="Unsupported number of texture formats: 2"):
with Image.open(io.BytesIO(data)):
pass
4 changes: 3 additions & 1 deletion src/PIL/FtexImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def _open(self) -> None:

# Only support single-format files.
# I don't know of any multi-format file.
assert format_count == 1
if format_count != 1:
msg = f"Unsupported number of texture formats: {format_count}"
raise ValueError(msg)

format, where = struct.unpack("<2i", self.fp.read(8))
self.fp.seek(where)
Expand Down