Skip to content

Unanticipated UnicodeDecodeError raised during call to PIL.Image.open #8956

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gabe-sherman opened this issue May 14, 2025 · 1 comment · May be fixed by #8958
Open

Unanticipated UnicodeDecodeError raised during call to PIL.Image.open #8956

gabe-sherman opened this issue May 14, 2025 · 1 comment · May be fixed by #8958

Comments

@gabe-sherman
Copy link

gabe-sherman commented May 14, 2025

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
@radarhere radarhere linked a pull request May 15, 2025 that will close this issue
@radarhere
Copy link
Member

I've created #8958

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants