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

Fixed processing multiple JPEG EXIF markers #8127

Merged
merged 2 commits into from
Jun 28, 2024

Conversation

radarhere
Copy link
Member

Resolves #8116

#7496 added concatenating of multiple JPEG EXIF markers.

However, the resulting image may not have the correct data in getexif(), as getexif() might be called after reading the first EXIF marker in attempt to read the DPI

if "dpi" not in self.info and "exif" in self.info:
try:
exif = self.getexif()

and getexif() is cached from that point on.

Pillow/src/PIL/Image.py

Lines 1479 to 1488 in 53e82e4

def getexif(self) -> Exif:
"""
Gets EXIF data from the image.
:returns: an :py:class:`~PIL.Image.Exif` object.
"""
if self._exif is None:
self._exif = Exif()
elif self._exif._loaded:
return self._exif

So this PR moves the DPI reading until after all markers are processed.


I've updated the test image from #7496, using the following code.

>>> from PIL import Image
>>> exif = Image.Exif()
>>> exif[270] = "firstsecond"
>>> exif.tobytes()
b'Exif\x00\x00MM\x00*\x00\x00\x00\x08\x00\x01\x01\x0e\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x1a\x00\x00\x00\x00firstsecond\x00'
im = Image.new("L", (1, 1))
im.save("Tests/images/multiple_exif.jpg", exif=b'Exif\x00\x00MM\x00*\x00\x00\x00\x08\x00\x01\x01\x0e\x00\x02\x00\x00\x00\x0c\x00\x00\x00\x1a\x00\x00\x00\x00first', extra=b'\xFF\xE1\x00\x0FExif\x00\x00second\x00')

src/PIL/JpegImagePlugin.py Outdated Show resolved Hide resolved
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
@radarhere radarhere merged commit 70b3815 into python-pillow:main Jun 28, 2024
54 of 56 checks passed
@radarhere radarhere deleted the multiple_exif_markers branch June 28, 2024 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-segment EXIF fails to read
2 participants