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

Error reading EXIF from file: SyntaxError: not a TIFF file (header b'' not valid) #8348

Closed
zakajd opened this issue Sep 5, 2024 · 3 comments · Fixed by #8350
Closed

Error reading EXIF from file: SyntaxError: not a TIFF file (header b'' not valid) #8348

zakajd opened this issue Sep 5, 2024 · 3 comments · Fixed by #8350
Labels

Comments

@zakajd
Copy link
Contributor

zakajd commented Sep 5, 2024

What did you do?

Tried to load image (attached below) and rotate it using image = ImageOps.exif_transpose(image)
Related to #4852 and #6123

What did you expect to happen?

Image rotated according to EXIF

What actually happened?

Processing failed with an error due to EXIF metadata being broken. Looking at exif information, I see it contains a duplicate Exif\x00\x00Exif\x00\x00 at the beginning. This image is uploaded by one of the clients, so I don't know how exactly that happened.

b'Exif\x00\x00Exif\x00\x00II*\x00\x08\x00\x00\x00\x06\x00\x12\x01\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00\x1a\x01\x05\x00\x01\x00\x00\x00V\x00\x00\x00\x1b\x01\x05\x00\x01\x00\x00\x00^\x00\x00\x00(\x01\x03\x00\x01\x00\x00\x00\x02\x00\x00\x00\x13\x02\x03\x00\x01\x00\x00\x00\x01\x00\x00\x00i\x87\x04\x00\x01\x00\x00\x00f\x00\x00\x00\x00\x00\x00\x00H\x00\x00\x00\x01\x00\x00\x00H\x00\x00\x00\x01\x00\x00\x00\x06\x00\x00\x90\x07\x00\x04\x00\x00\x000210\x01\x91\x07\x00\x04\x00\x00\x00\x01\x02\x03\x00\x00\xa0\x07\x00\x04\x00\x00\x000100\x01\xa0\x03\x00\x01\x00\x00\x00\xff\xff\x00\x00\x02\xa0\x04\x00\x01\x00\x00\x00\x08\x07\x00\x00\x03\xa0\x04\x00\x01\x00\x00\x00\x08\x07\x00\x00\x00\x00\x00\x00'

exiftool shows there is error with exif
Warning : Malformed APP1 EXIF segment

What are your OS, Python and Pillow versions?

  • OS: MacOS
  • Python: 3.10
  • Pillow: 10.2.0
Please paste here the output of running:
Pillow 10.2.0
Python 3.10.14 (main, Mar 19 2024, 21:46:16) [Clang 15.0.0 (clang-1500.3.9.4)]
--------------------------------------------------------------------
Python modules loaded from /opt/homebrew/lib/python3.10/site-packages/PIL
Binary modules loaded from /opt/homebrew/lib/python3.10/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 10.2.0
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.3
--- LITTLECMS2 support ok, loaded 2.16
--- WEBP support ok, loaded 1.4.0
--- WEBP Transparency support ok
--- WEBPMUX support ok
--- WEBP Animation support ok
--- JPEG support ok, compiled for libjpeg-turbo 3.0.2
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.2
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.12
--- LIBTIFF support ok, loaded 4.6.0
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
image = Image.open("broken_exif.jpg")
image = ImageOps.exif_transpose(image)

Image itself
broken_exif

@radarhere
Copy link
Member

For an immediate solution, you can use this code to repair the EXIF data yourself.

from PIL import Image, ImageOps
image = Image.open("in.jpg")
if "exif" in image.info and image.info["exif"].startswith(b"Exif\x00\x00Exif\x00\x00"):
    image.info["exif"] = image.info["exif"][6:]
image = ImageOps.exif_transpose(image)
image.save("out.jpg")

@radarhere radarhere added the Exif label Sep 5, 2024
@radarhere
Copy link
Member

This image is uploaded by one of the clients, so I don't know how exactly that happened.

If this is just a single image, not something that has happened repeatedly, is it possible to just accept that this is broken, and not something that Pillow needs to handle?

exiftool agrees that it is malformed, so it's not just us that think so.

This specific image, the only one you know of with this problem, isn't even transposed when the data is correctly parsed. The image retains its original orientation - meaning that just catching the error

from PIL import Image, ImageOps
image = Image.open('in.jpg')
try:
    image = ImageOps.exif_transpose(image)
except Exception:
    pass

would actually serve you equally well.

@zakajd
Copy link
Contributor Author

zakajd commented Sep 5, 2024

There are actually 3 similar images with the same problem that were uploaded, I attached a single one for simplicity. I will add the try .. .except block logic, just wanted to push a workaround if anyone will meet same problem in the future

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

Successfully merging a pull request may close this issue.

2 participants