Skip to content
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

Do not set size unnecessarily if image fails to open #7056

Merged
merged 1 commit into from
Jun 13, 2023

Conversation

radarhere
Copy link
Member

When opening an image, if the size is missing, EpsImagePlugin sets the image size just before throwing an error.

if not self._size:
self._size = 1, 1 # errors if this isn't set. why (1,1)?
msg = "cannot determine EPS bounding box"
raise OSError(msg)

But if an error is thrown when opening, there is no image afterwards. Consider this example code, derived from the test suite.

import io
from PIL import Image

data = io.BytesIO(b'%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: a b c d\n10 setlinewidth\n10 10 moveto\n0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath\nstroke')
try:
    im = Image.open(data)
except OSError:
    pass
print(im)

gives

Traceback (most recent call last):
  File "demo.py", line 9, in <module>
    print(im)
NameError: name 'im' is not defined

So if there is no image afterwards, why does it need a size? This PR removes the line.

@hugovk hugovk merged commit 0c7061e into python-pillow:main Jun 13, 2023
@radarhere radarhere deleted the eps branch June 13, 2023 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants