Skip to content

Commit 9e282f5

Browse files
authored
Raise ValueError instead of asserting number of FTEX texture formats (#9805)
1 parent b741b77 commit 9e282f5

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Tests/test_file_ftex.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,13 @@ def test_invalid_texture() -> None:
3838
with pytest.raises(ValueError, match="Invalid texture compression format: 2"):
3939
with Image.open(io.BytesIO(data)):
4040
pass
41+
42+
43+
def test_unsupported_texture_format_count() -> None:
44+
with open("Tests/images/ftex_dxt1.ftc", "rb") as fp:
45+
# Change the format count to an unsupported value
46+
data = fp.read(20) + struct.pack("<i", 2)
47+
48+
with pytest.raises(ValueError, match="Unsupported number of texture formats: 2"):
49+
with Image.open(io.BytesIO(data)):
50+
pass

src/PIL/FtexImagePlugin.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ def _open(self) -> None:
8282

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

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

0 commit comments

Comments
 (0)