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

Backward seek on closed GifImageFile breaks expected behaviour #6205

Closed
AnonymouX47 opened this issue Apr 12, 2022 · 3 comments · Fixed by #6213
Closed

Backward seek on closed GifImageFile breaks expected behaviour #6205

AnonymouX47 opened this issue Apr 12, 2022 · 3 comments · Fixed by #6213

Comments

@AnonymouX47
Copy link

AnonymouX47 commented Apr 12, 2022

What did you do?

  • Opened a GIF image from a file
  • Seeked forward
  • Closed the image
  • Tried to seek backward
  • Tried to load the image

What did you expect to happen?

After the image was closed, I expected all operations that involve loading or mutation to raise ValueError: Operation on closed image.
I tested WebPImageFile and it behaved as expected.

SInce PIL.Image.Image provides no public interface to determine if an image is closed or not, the next point of call would be trying an operation on the image to see if a specific exception is raised. The inconsistency shown above breaks that behaviour.

What actually happened?

Operations on the closed image don't raise the expected exception after seeking backward.

What are your OS, Python and Pillow versions?

  • OS: Pop OS 21.10 (Linux)
  • Python: 3.9.10
  • Pillow: 9.1.0
from PIL import Image

img = Image.open("tests/images/lion.gif")
img.seek(4)  # Ok
img.close()  # Ok
img.load()  # Ok; ValueError: Operation on closed image
img.seek(5)  # Ok; ValueError: Operation on closed image
img.seek(0)  # Not Ok; AttributeError: 'NoneType' object has no attribute 'seek'
img.tell()  # Not Ok; -1
img.seek(5)  # Not Ok; AttributeError: 'NoneType' object has no attribute 'seek'
img.load()  # Not Ok; AttributeError: 'NoneType' object has no attribute 'read'
@AnonymouX47
Copy link
Author

I don't think this is an issue that could come up often but there's also the possibility of it coming up.

@AnonymouX47 AnonymouX47 changed the title Backward seek on closed GifImageFile breaks expected behaviour Backward seek on closed GifImageFile breaks expected behaviour Apr 12, 2022
@radarhere
Copy link
Member

I've created PR #6213 to resolve this.

@AnonymouX47
Copy link
Author

Thanks 😃

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