Repository: python-pillow/Pillow

Problem statement:
getexif() crashes when reading empty EXIF data from a PNG file saved by RawTherapy 5.8
### What did you do?
Converted a RAW file to PNG using RawTherapy 5.8.
Opened the image file with Pillow and called getexif()

### What did you expect to happen?
Since the file has no EXIF data, the expected output is None or an empty dictionary.
`pyexiv2` returns an empty dictionary.

### What actually happened?
```
Traceback (most recent call last):
  File "/home/roman/Projects/pillow-png-getexif/read_png_exif.py", line 8, in <module>
    exif = img.getexif()
  File "/home/roman/Projects/mikula/venv/lib/python3.8/site-packages/PIL/PngImagePlugin.py", line 951, in getexif
    self._exif.load(exif_info)
  File "/home/roman/Projects/mikula/venv/lib/python3.8/site-packages/PIL/Image.py", line 3271, in load
    self._info = TiffImagePlugin.ImageFileDirectory_v1(self.head)
  File "/home/roman/Projects/mikula/venv/lib/python3.8/site-packages/PIL/TiffImagePlugin.py", line 900, in __init__
    super().__init__(*args, **kwargs)
  File "/home/roman/Projects/mikula/venv/lib/python3.8/site-packages/PIL/TiffImagePlugin.py", line 466, in __init__
    raise SyntaxError("not a TIFF file (header %r not valid)" % ifh)
SyntaxError: not a TIFF file (header b'\x00\x00\x11\x00\x00\x01\x04\x00' not valid)
```

### What are your OS, Python and Pillow versions?
* OS:  Ubuntu 20.04
* Python: Python version 3.8.2 [GCC 9.3.0]
* Pillow: 7.1.1

```python
fn = "mug_small.png"
img = Image.open(fn)
exif = img.getexif()
```
The code and the test image are available on [github](https://github.com/RomanKosobrodov/pillow-png-getexif).


Hints:
The file actually does have EXIF data. It may not have an eXIf chunk, but it has a zTXt chunk, "Raw profile type exif". See https://exiftool.org/TagNames/PNG.html#TextualData for some more information.

Pillow has an assumption that EXIF data starts with "Exif\x00\x00", but that is not the case for your image. Here is some code as a demonstration.

```python
from PIL import Image
img = Image.open("mug_small.png")
if "Raw profile type exif" in img.info:
	rawProfileTypeExif = bytes.fromhex(
		"".join(img.info["Raw profile type exif"].split("\n")[3:])
	)
	if rawProfileTypeExif[:6] != "Exif\x00\x00":
		print("Fix missing EXIF prefix")
		img.info["exif"] = b"Exif\x00\x00"+rawProfileTypeExif
exif = img.getexif()
print(exif)
```

Patch:
diff --git a/src/PIL/Image.py b/src/PIL/Image.py
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -3289,7 +3289,9 @@ def load(self, data):
         if not data:
             return
 
-        self.fp = io.BytesIO(data[6:])
+        if data.startswith(b"Exif\x00\x00"):
+            data = data[6:]
+        self.fp = io.BytesIO(data)
         self.head = self.fp.read(8)
         # process dictionary
         from . import TiffImagePlugin


Test patch:
diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py
--- a/Tests/test_file_webp_metadata.py
+++ b/Tests/test_file_webp_metadata.py
@@ -30,6 +30,15 @@ def test_read_exif_metadata():
             assert exif_data == expected_exif
 
 
+def test_read_exif_metadata_without_prefix():
+    with Image.open("Tests/images/flower2.webp") as im:
+        # Assert prefix is not present
+        assert im.info["exif"][:6] != b"Exif\x00\x00"
+
+        exif = im.getexif()
+        assert exif[305] == "Adobe Photoshop CS6 (Macintosh)"
+
+
 def test_write_exif_metadata():
     file_path = "Tests/images/flower.jpg"
     test_buffer = BytesIO()