From 35d7af83bd778bab2072b58d0e15d7adc283d236 Mon Sep 17 00:00:00 2001 From: Ritika shrestha <87307821+ritsth@users.noreply.github.com> Date: Mon, 20 Jul 2026 18:01:32 -0700 Subject: [PATCH 1/2] Raise ValueError instead of asserting on FTEX format count --- Tests/test_file_ftex.py | 12 ++++++++++++ src/PIL/FtexImagePlugin.py | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Tests/test_file_ftex.py b/Tests/test_file_ftex.py index fdd7b375762..0130651b1bf 100644 --- a/Tests/test_file_ftex.py +++ b/Tests/test_file_ftex.py @@ -38,3 +38,15 @@ def test_invalid_texture() -> None: with pytest.raises(ValueError, match="Invalid texture compression format: 2"): with Image.open(io.BytesIO(data)): pass + + +def test_invalid_format_count() -> None: + with open("Tests/images/ftex_dxt1.ftc", "rb") as fp: + data = fp.read() + + # Change the format count to an unsupported value + data = data[:20] + struct.pack(" 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 formats: {format_count}" + raise ValueError(msg) format, where = struct.unpack("<2i", self.fp.read(8)) self.fp.seek(where) From b4a82a8b52dbbc2132d29de8d5ae371114bf5f7e Mon Sep 17 00:00:00 2001 From: Ritika shrestha <87307821+ritsth@users.noreply.github.com> Date: Wed, 22 Jul 2026 11:54:07 -0700 Subject: [PATCH 2/2] Specify "texture formats" in error message --- Tests/test_file_ftex.py | 10 ++++------ src/PIL/FtexImagePlugin.py | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Tests/test_file_ftex.py b/Tests/test_file_ftex.py index 0130651b1bf..99cf36a6ffe 100644 --- a/Tests/test_file_ftex.py +++ b/Tests/test_file_ftex.py @@ -40,13 +40,11 @@ def test_invalid_texture() -> None: pass -def test_invalid_format_count() -> None: +def test_unsupported_texture_format_count() -> None: with open("Tests/images/ftex_dxt1.ftc", "rb") as fp: - data = fp.read() - - # Change the format count to an unsupported value - data = data[:20] + struct.pack(" None: # Only support single-format files. # I don't know of any multi-format file. if format_count != 1: - msg = f"Unsupported number of formats: {format_count}" + msg = f"Unsupported number of texture formats: {format_count}" raise ValueError(msg) format, where = struct.unpack("<2i", self.fp.read(8))