Skip to content

Concatenate multiple JPEG EXIF markers#7496

Merged
hugovk merged 1 commit intopython-pillow:mainfrom
radarhere:exif
Dec 31, 2023
Merged

Concatenate multiple JPEG EXIF markers#7496
hugovk merged 1 commit intopython-pillow:mainfrom
radarhere:exif

Conversation

@radarhere
Copy link
Member

Resolves #7495

The issue has found an image where multiple EXIF markers are present. This is against the specification -

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.

but this PR allows Pillow to be more flexible, and concatenates the two markers.

I created a test image with

from PIL import Image im = Image.new("L", (1, 1)) im.save("multiple_exif.jpg", exif=b"Exif\x00\x00first", extra=b"\xFF\xE1\x00\x0EExif\x00\x00second")
if "exif" not in self.info:
# extract EXIF information (incomplete)
self.info["exif"] = s # FIXME: value will change
elif marker == 0xFFE1 and s[:6] == b"Exif\0\0":
Copy link
Member

@homm homm Nov 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why extra \0 here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I am removing 6 bytes of the EXIF prefix when concatenating subsequent markers, it makes sense to me to check that the 6-byte prefix is present.

@hugovk hugovk merged commit 6c4b47d into python-pillow:main Dec 31, 2023
@radarhere radarhere deleted the exif branch January 1, 2024 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants