-
Notifications
You must be signed in to change notification settings - Fork 253
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
Calling pdf.image()
might closes passed BytesIO object
#881
Comments
Thank you for the detailed report @Niwo1403!
Agreed! I introduced that change in PR #721 as an attempt to avoid memory leaks. We should only close |
This is indeed a side effect of print(img_bytes.closed) # False
img = Image.open(img_bytes)
img.close()
print(img_bytes.closed) # True It's done there in Pillow source code: |
I opened #887 to fix this |
Fixed! While waiting for a new
|
@allcontributors please add @Niwo1403 for bug |
I've put up a pull request to add @Niwo1403! 🎉 |
If
pdf.image()
gets called with a BytesIO object this object might be closed while processing (making the bytes in it unavailable after the execution of the method). Whether the object will be closed depends on the image format (e.g. PNG will be closed, JPG not). Since this might break compatibility with previous versions and acts differently depending on the image format, I assume this is not done on purpose, right?Error details
Raised error:
Reason for error:
First appearance of error:
I think this error was added in this commit around 5 months ago and is included since version 2.7.0.
Minimal code
Environment
fpdf2
version used: 2.7.5 & current masterThe text was updated successfully, but these errors were encountered: