Skip to content

Image.getexif() errors on n04532106_1553.JPEG from ImageNet #8957

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

Open
iperminov-mythic opened this issue May 14, 2025 · 5 comments · May be fixed by #8960
Open

Image.getexif() errors on n04532106_1553.JPEG from ImageNet #8957

iperminov-mythic opened this issue May 14, 2025 · 5 comments · May be fixed by #8960

Comments

@iperminov-mythic
Copy link

This image file seems to have invalid utf-8 in xmp tags and getexif errors with

Traceback (most recent call last):
  File "/.../lib/python3.10/site-packages/PIL/Image.py", line 1542, in getexif
    xmp_tags = xmp_tags.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa8 in position 4312: invalid start byte

This is not technically a bug, but it may be better to print a warning instead of throwing an error. ImageNet is a popular dataset and this issue is going to be painful for its users.

The issue only happens with Pillow 11.2.1, because the previous versions do not have this UTF decoding step.
7d50816#diff-4805c79264fea07df59058db82ed74bb2f5c5023e212ac678536a534c56e5be2R1524

@iperminov-mythic iperminov-mythic changed the title Image.getexif() error on n04532106_1553.JPEG from ImageNet Image.getexif() errors on n04532106_1553.JPEG from ImageNet May 14, 2025
@radarhere
Copy link
Member

Could you attach the image?

@iperminov-mythic
Copy link
Author

I tried to figure out if I am allowed to share the image and am not sure. I think this says images can't be shared publicly. https://image-net.org/download.php

@iperminov-mythic
Copy link
Author

Image Here is a test image that has the same bad metadata as n04532106_1553.JPEG.

@iperminov-mythic
Copy link
Author

iperminov-mythic commented May 14, 2025

Here is a code snippet to reproduce the issue

from PIL import Image
im = Image.open('443876244-4cdf2ebc-88c4-4a61-b99e-f78d07c49bfe.JPEG')
im.getexif()

It results in

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../lib/python3.10/site-packages/PIL/Image.py", line 1542, in getexif
    xmp_tags = xmp_tags.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa8 in position 4312: invalid start byte

@radarhere radarhere linked a pull request May 15, 2025 that will close this issue
@radarhere
Copy link
Member

I've created #8960 to resolve this.

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

Successfully merging a pull request may close this issue.

2 participants