-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Random crashes of python in latest dev version of Pillow with pillow_heif #8439
Comments
This sort of thing sounds like a memory safety issue. It's possible that just running to crash under gdb would be enough to tell you where the crash is happening, and that should be enough to start to narrow down the issue. Alternately, you can run under valgrind on linux (but that's slow). If it's a consistent failure, the other option is to use git bisect and narrow down to the commit -- though since we don't squash commits on main, there's a chance of having non-working commits unrelated to this at any given point. |
additional information that I may have forgotten to mention is that
thanks, very good finding |
It turns out that when the second frame has a different mode, a new Edit: the reason is correct(wrong mode for Line 887 in 51c577d
Can we revert this commit 84e275d ? |
History says that this hasn't changed since the PIL fork, except for the most recent batch of changes. I can see where we could get multi image container formats (gif or webpanim or tiff) where the frame type could change, esp something like rgb->rgba, though our internal decoders might handle that directly. Obviously at least one external decoder has been relying on this. I'd say revert, but finding a good test case for this might be the hardest bit. |
My commit was inspired by @homm's comment that he considered it a bug when an image changed size after it was loaded. I think from PIL import Image
im = Image.open(...)
print(im.mode) # L
print(im.copy().mode) # RGB When I made the mode change, none of our internal plugins had to be updated to handle it. GifImagePlugin changes modes between frames, sure, but the the core image can be reset before loading, in its own @bigcat88 a few questions - do you disagree with my idea in theory? Do you think pillow_heif could be updated handle this new way of doing things? Is the problem simply that this change was made suddenly, and you would prefer a deprecation? |
I don't know how common it is that frames have different modes.
I don't mind updating "pillow_heif", that's why I created issue to determine the way to do it, knowing that here everyone can always get an answer to the question of what is best
After receiving a hint that TiffImagePlugin does this in the seek method, in theory it should be done the same way. Like this: def seek(self, frame: int):
if not self._seek_check(frame):
return
self.__frame = frame
self._init_from_heif_file(frame) # this fills `self._size` and `self._mode` with new frame info
if pil_version[:3] != "10.":
# Pillow 11.0+
# We need to create a new core image object on second and
# subsequent frames in the image. Image may be different size/mode.
# https://github.com/python-pillow/Pillow/issues/8439
self.im = Image.core.new(self._mode, self._size)
_exif = getattr(self, "_exif", None) # Pillow 9.2+ do no reload exif between frames.
if _exif is not None and getattr(_exif, "_loaded", None):
_exif._loaded = False # pylint: disable=protected-access It seems to work and tests passed successfully, many thanks to everyone for help. I think the issue can be closed? |
I still think it's better to revert this, especially now, when we realise not only TiffImagePlugin relies on this behaviour. |
Reverted and deprecated? I think the ideal behaviour when changing modes between frames is actually to set |
This will lead to unnecessary memory allocation if all frames have the same size and mode. The previous implementation of
I fully agree, just like with size changes, which I also tried to fix, as you might remember. But I don't quite understand how this would happen if we return to the previous
Possibly. But I'm specifically talking about |
Returning to the previous If you're not a fan of that suggestion though, then I'm happy to just revert the |
Good point. I'll take a look. |
Good day, everyone.
I'll try to describe the situation briefly.
First, I want to clarify that I'm not certain this is a bug in Pillow. I created this issue so that knowledgeable contributors could help identify any recent changes in the repository that might be causing the problem I'm experiencing.
About two weeks ago, when using the development version of Pillow, some actions in pillow_heif repo started to fail: run link.
Now that I have some time to investigate, I'm encountering a situation where the root cause of the error is still unclear to me.
Here is the script I'm using for testing:
It can crash, or sometimes it does not crash.
Sometimes I even see "exit" in output and then crash occurs.
I'm running this script from the cloned
pillow_heif
repository, creating a "dev" folder at the root (if needed for quick reproduction) and placing it there.The issue is that my Python interpreter randomly crashes when using the development version of Pillow, and I haven't been able to pinpoint the exact location of the crash.
Nothing has changed in
pillow_heif
itself in last months (I'm waiting for HDR image support before refactoring the code).I've tried running the script with other versions of Pillow, and everything works fine. I've also tried adding print statements inside Pillow to locate the failure, but the crash seems random, and I haven't been able to identify the exact spot where it occurs.
I'm testing this on macOS (but can also reproduce it on Linux). Any insights or tips on where to investigate, or information on what may have changed in the Pillow repo 2–3 weeks ago that could lead to these crashes, would be greatly appreciated.
Some info that I have found:
1ee3bd1 - on this commit crash already occurs
08d9c89 - repo at this commit is good
Thank you!
The text was updated successfully, but these errors were encountered: