-
- Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
What did you do?
load a image and its exif is b'Exif\x00\x00'
im=Image.open(/path/to/img) im._exif is NoneTrue im.info{'jfif': 257, 'jfif_version': (1, 1), 'dpi': (1, 1), 'jfif_unit': 1, 'jfif_density': (1, 1), 'exif': b'Exif\x00\x00'} im.getexif()Traceback (most recent call last): File "/home/me/anaconda3/envs/ppdetection213/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3444, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "/tmp/ipykernel_15028/2749469980.py", line 1, in <module> im.getexif() File "/home/me/anaconda3/envs/ppdetection213/lib/python3.9/site-packages/PIL/Image.py", line 1391, in getexif self._exif.load(exif_info) File "/home/me/anaconda3/envs/ppdetection213/lib/python3.9/site-packages/PIL/Image.py", line 3422, in load self._info = TiffImagePlugin.ImageFileDirectory_v2(self.head) File "/home/me/anaconda3/envs/ppdetection213/lib/python3.9/site-packages/PIL/TiffImagePlugin.py", line 491, in __init__ raise SyntaxError(f"not a TIFF file (header {repr(ifh)} not valid)") File "<string>", line unknown SyntaxError: not a TIFF file (header b'' not valid) What did you expect to happen?
Nothing to be done. Since functions like ImageOps.exif_transpose calls im.getexif(), so I will expect that no errors should be raised.
What actually happened?
the getexif() function will call Exif() to initiate a blank Exif instance, since the im._exif is None. And then the Exif() instance will load the im.info.get('exif'), which is b'Exif\x00\x00'. In the load function, the b'Exif\x00\x00' will be dropped by this line. So a b'' is passed to TiffImagePlugin.ImageFileDirectory_v2(self.head). And since b'' is not accepted by TiffImagePlugin.ImageFileDirectory_v2, an error will be raised.
BTW, these three lines in Exif.load():
if data == self._loaded_exif: return self._loaded_exif = datamake the code work when calling im.getexif() the second time.
What are your OS, Python and Pillow versions?
- OS: Linux
- Python: 3.9.7
- Pillow: 8.4.0 and 9.0.1
im=Image.open(/path/to/img) im.getexif()I wonder if this repo is considering returning a blank Exif in this case, instead of raising an error. I have no idea whether this would lead to other unknown damages or not.
