Open
Description
When the below code is run, a UnicodeDecodeError
is raised when attempting to raise a ValueError
with a descriptive message to the user. This occurs in _read_token
at line 97 in PpmImagePlugin.py.
Minimal Reproducer
import sys
import io
import PIL.Image
d = io.BytesIO(b'P3\x0cAAAAAAAAAA\xee')
PIL.Image.open(d)
Version Info
11.2.1
Traceback Report
File "rep.py", line 6, in <module>
PIL.Image.open(d)
File "lib/python3.10/site-packages/PIL/Image.py", line 3551, in open
im = _open_core(fp, filename, prefix, formats)
File "lib/python3.10/site-packages/PIL/Image.py", line 3539, in _open_core
im = factory(fp, filename)
File "lib/python3.10/site-packages/PIL/ImageFile.py", line 147, in __init__
self._open()
File "/lib/python3.10/site-packages/PIL/PpmImagePlugin.py", line 119, in _open
self._size = int(self._read_token()), int(self._read_token())
File "lib/python3.10/site-packages/PIL/PpmImagePlugin.py", line 97, in _read_token
msg = f"Token too long in file header: {token.decode()}"
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xee in position 10: unexpected end of data
Metadata
Metadata
Assignees
Labels
No labels