Handle duplicate EXIF header by jzakirov · Pull Request #8350 · python-pillow/Pillow

@jzakirov

Fixes #8348

Changes proposed in this pull request:

  • Explicitly check for double exif info and drop it

@radarhere radarhere changed the title Handle dublicate exif header Handle duplicate EXIF header

Sep 5, 2024

radarhere

Comment on lines +3971 to +3973

if data and data.startswith(b"Exif\x00\x00Exif\x00\x00"):
data = data[12:]
elif data and data.startswith(b"Exif\x00\x00"):

Choose a reason for hiding this comment

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

if data and data.startswith(b"Exif\x00\x00Exif\x00\x00"):
data = data[12:]
elif data and data.startswith(b"Exif\x00\x00"):
while data and data.startswith(b"Exif\x00\x00"):

This seems simpler to me.

Choose a reason for hiding this comment

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

Done. Also added test for this problem as well

@radarhere

In the issue, you said

This image is uploaded by one of the clients

Are you sure that this is an image that can be distributed under the Pillow license?

@jzakirov

Good point. I'm not a lawyer, to be safe will manually create an image where the EXIF is broken same way.

@radarhere @jzakirov

Co-authored-by: Jamil Zakirov <djamilzak@gmail.com>

radarhere

@jzakirov