Pillow
Pillow copied to clipboard
Handle truncated chunks at the end of PNG images
Fix png image plugin load_end func handle truncated file.
When attempting to process PNG image files that are incomplete at the end, the current LOAD_TRUNCATED_IMAGES parameter is unable to handle such cases. It is necessary to add corresponding handling code within the load_end function to ensure proper processing of incomplete images. Below is a link to an example of such an anomalous image:
Changes proposed in this pull request:
- Fix PngImagePlugin.py load_end func, add exception handle.
cc @radarhere Can you help me with a code review? thanks a lot.
If you're interested in an immediate solution as an alternative to this PR, I find that you can just ignore the error and the image works fine.
from PIL import Image
im = Image.open('in.png')
try:
im.load()
except OSError:
pass
im.save("out.png")
I'm amazed by your quick response. Indeed, loading images by ignoring load exceptions can be a way to load and convert images into a normal state. Thank you for your suggestion. Are there any other suggested modifications for this pull request?
@radarhere
The test image that you've added is 721kb - this is a bit large.
Here's a test image I've created by modifying hopper_idat_after_image_end.png - it is only 30kb.
@radarhere The comments have all been fixed.
Do I need to perform any additional actions for this PR to be merged? @radarhere
I've just combined the commits in this PR into one so that your original image isn't part of the commit history.