Raise ValueError instead of asserting number of FTEX texture formats#9805
Conversation
|
So are you saying you actually encountered a multi-format file in the wild? |
|
I've created ritsth#1 with a suggestion. |
No, I haven't encountered one in the wild. I found this while reading through the FTEX plugin's _open() and noticed the assert format_count == 1 was being used for input validation rather than an internal invariant check. That's a problem regardless of whether a real multi-format file exists, since assert raises an undocumented AssertionError and disappears entirely under python -O, so malformed/truncated input could either crash confusingly or silently skip validation.
Also applied your wording suggestion from ritsth#1. Thanks! |
Resolves #9809
FtexImageFile._openusedassert format_count == 1to reject multi-format files. That raisesAssertionError, which is not one of the exceptions Pillow documents for unparseable files, so callers catchingUnidentifiedImageErrororValueErrordo not catch it; and underpython -Othe assert is stripped, so the file is parsed as if valid.This raises a
ValueErrorinstead, matching the existing "Invalid texture compression format" check in the same plugin. Added a regression test that patches the format count in a valid file, mirroringtest_invalid_texture.Used an AI assistant to find this; I reviewed and tested the change myself.