Skip to content
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

PIL.UnidentifiedImageError on png file #7504

Closed
MayankFawkes opened this issue Oct 30, 2023 · 4 comments
Closed

PIL.UnidentifiedImageError on png file #7504

MayankFawkes opened this issue Oct 30, 2023 · 4 comments

Comments

@MayankFawkes
Copy link

MayankFawkes commented Oct 30, 2023

What did you do?

Trying to open one png file

What did you expect to happen?

open and skip all the file checks

What actually happened?

returning error

What are your OS, Python and Pillow versions?

  • OS: WIN 11
  • Python: 3.10.11
  • Pillow: 10.0.1/10.1.0
from PIL import Image
import requests
from io import BytesIO

IMG_URL = "https://i.ibb.co/QN1JyLp/IMG-20231030-100421.png"

response = requests.get(IMG_URL)
image_object = BytesIO(response.content)

img = Image.open(image_object)
# do things here
img.show()

i tried some third party tools to check the PNG file. https://processing.compress-or-die.com/repair-process

1	Combined all IDAT chunks.
2	Fixed CRC checksum for chunk "eXIf".
3	Fixed CRC checksum for chunk "IDAT".

is there a way i can skip those checks in pillow, and just open it in insecure way of something.

@radarhere
Copy link
Member

You can set LOAD_TRUNCATED_IMAGES.

from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True

@MayankFawkes
Copy link
Author

MayankFawkes commented Oct 30, 2023

alright that's working, also @radarhere it would be great if you could explain a little about LOAD_TRUNCATED_IMAGES constant.

@radarhere
Copy link
Member

https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#png

By default Pillow doesn’t allow loading of truncated PNG files, set ImageFile.LOAD_TRUNCATED_IMAGES to override this.

https://pillow.readthedocs.io/en/stable/reference/ImageFile.html#PIL.ImageFile.LOAD_TRUNCATED_IMAGES

PIL.ImageFile.LOAD_TRUNCATED_IMAGES = False
Whether or not to load truncated image files. User code may change this.

As of #1991, the setting allows PNGs to skip bad PNG checksums.

@MayankFawkes
Copy link
Author

Alright thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants