Handle truncated chunks at the end of PNG images#7709
Handle truncated chunks at the end of PNG images#7709radarhere merged 7 commits intopython-pillow:mainfrom
Conversation
|
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? |
|
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. |
d306d20 to
98dc9ac
Compare
for more information, see https://pre-commit.ci
Test error is raised without LOAD_TRUNCATED_IMAGES
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>

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:
cc @radarhere Can you help me with a code review? thanks a lot.