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

Multi-segment Exif fails to read #7495

Closed
worthlesscog opened this issue Oct 25, 2023 · 2 comments · Fixed by #7496
Closed

Multi-segment Exif fails to read #7495

worthlesscog opened this issue Oct 25, 2023 · 2 comments · Fixed by #7496

Comments

@worthlesscog
Copy link

What did you do?

Writing code to read ai generated images and tried to get User Comment field from EXIF data contained in an image opened with Image.open. The jpeg image is as far as I can tell not corrupt. ExifTool reads it OK and shows me the comment with a minor warning that "File contains multi-segment EXIF." I can see the User Comment listed in the console with ExifTool. It's large, but looks OK.

What did you expect to happen?

User Comment field to be read and returned.

What actually happened?

Using image.getexif().get_ifd(ExifTags.IFD.Exif) returns an empty dict along with this warning on the console-
python3.11/site-packages/PIL/TiffImagePlugin.py:868: UserWarning: Truncated File Read

What are your OS, Python and Pillow versions?

  • OS: Linux pop-os 6.2.6-76060206-generic (Ubuntu compatible with 22 I think)
  • Python: 3.11
  • Pillow: 10.1.0
with Image.open("03d2695a.jpeg") as i:
    x = i.getexif().get_ifd(ExifTags.IFD.Exif)

03d2695a.jpeg.zip

@radarhere
Copy link
Member

https://en.wikipedia.org/wiki/Exif

Exif metadata are restricted in size to 64 kB in JPEG images because according to the specification this information must be contained within a single JPEG APP1 segment.

So this image is actually incorrect. However, I've created PR #7496 to make Pillow more flexible and combine the EXIF markers.

@worthlesscog
Copy link
Author

Oh, that was quick, thank you. I didn't know it was outside the spec. It wasn't my image so I have no idea which tool produced it.

I'd done some searches before and saw a post by Phil on the ExifTool forum saying multi-segment Exif wasn't well supported but didn't actually say it was incorrect. ExifTool lists it as a minor warning.

For reference -
https://exiftool.org/forum/index.php?topic=9512.msg49283#msg49283

Awesome, thanks again.

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

Successfully merging a pull request may close this issue.

2 participants