Random crashes of python in latest dev version of Pillow with pillow_heif #8439
Description
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:
import os
import pillow_heif
from pathlib import Path
from PIL import Image, ImageSequence
pillow_heif.register_heif_opener()
os.chdir(Path(__file__).parent.parent.joinpath("tests/images/heif/"))
if __name__ == "__main__":
im = Image.open("zPug_3.heic")
im.load()
for frame in ImageSequence.Iterator(im):
print("before frame.load()")
frame.load()
print("after frame.load()")
assert len(frame.tobytes()) > 0
print("after frame.tobytes()")
print("exit")
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!