Repository: python-pillow/Pillow

Issue:
Inconsistent XMP data retrieval: Failure with specific JPEG files
### What did you do?
I'm loading a .jpg image using Pillow in an attempt to extract the XMP metadata:
```python
from PIL import Image

image = Image.open("lib/filename_example_1.jpg")
raw_xmp_info = image.getxmp()
``` 

### What did you expect to happen?
I'm expecting `getxmp()` to return a dictionary containing the image's XMP metadata: `{'xmpmeta: {<metadata>}`. 

### What actually happened?
Pillow can't extract the XMP metadata from the image: 
```pytb
Traceback (most recent call last):
  File "/path/to/main.py", line 4, in <module>
    raw_xmp_info = image.getxmp()
                   ^^^^^^^^^^^^^^
  File "/path/to/venv/site-packages/PIL/JpegImagePlugin.py", line 501, in getxmp
    return self._getxmp(xmp_tags)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/site-packages/PIL/Image.py", line 1410, in _getxmp
    return {get_name(root.tag): get_value(root)}
                                ^^^^^^^^^^^^^^^
  File "/path/to/venv/site-packages/PIL/Image.py", line 1391, in get_value
    child_value = get_value(child)
                  ^^^^^^^^^^^^^^^^
  File "/path/to/venv/site-packages/PIL/Image.py", line 1391, in get_value
    child_value = get_value(child)
                  ^^^^^^^^^^^^^^^^
  File "/path/to/venv/site-packages/PIL/Image.py", line 1386, in get_value
    value = {get_name(k): v for k, v in element.attrib.items()}
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/venv/site-packages/PIL/Image.py", line 1386, in <dictcomp>
    value = {get_name(k): v for k, v in element.attrib.items()}
             ^^^^^^^^^^^
  File "/path/to/venv/site-packages/PIL/Image.py", line 1383, in get_name
    return tag.split("}")[1]
           ~~~~~~~~~~~~~~^^^
IndexError: list index out of range
``` 

### What are your OS, Python and Pillow versions?

* OS: WSL2 - Ubuntu 22.04.2 LTS
* Python: 3.11.4
* Pillow: 10.0.0 (also getting the error with 9.x)

### Additional information. 
Printing `image.info` reveals: 
```python
{'jfif': 257, 'jfif_version': (1, 1), 'dpi': (240, 240), 'jfif_unit': 1, 'jfif_density': (240, 240), 'photoshop': {1028: b'\x1c\x02\x00\x00\x02\x00\x02\x1c\x01Z\x00\x03\x1b%G\x1c\x02i\x00\x1f"Enkeltrick"-Betrug vor Gericht\x1c\x02\x19\x00\x14.Nordrhein-Westfalen\x1c\x02\x19\x00\x03Ges\x1c\x02\x19\x00\rKriminalit\xc3\xa4t\x1c\x02\x19\x00\x03lnw\x1c\x02\x19\x00\x08Prozesse\x1c\x02\x19\x00\tRegierung\x1c\x02\x19\x00\x08Senioren\x1c\x02\x19\x00\nSicherheit\x1c\x02\x19\x00\x07Telefon\x1c\x02\x19\x00\x0bVermischtes\x1c\x02\x19\x00\x0c\xc3\x9cberwachung\x1c\x02\x19\x00\x12\xc3\x9cberwachungsstaat\x1c\x02\x19\x00\x07XGV2011\x1c\x02Z\x00\x07Dresden\x1c\x02_\x00\x07Sachsen\x1c\x02e\x00\x0bDeutschland\x1c\x02d\x00\x03DEU\x1c\x027\x00\x0820131216\x1c\x02P\x00\nArno Burgi\x1c\x02t\x00-picture alliance / Arno Burgi/dpa-Zentralbild\x1c\x02z\x00\x17abu vfd htf kno sup bsc\x1c\x02n\x00-picture alliance / Arno Burgi/dpa-Zentralbild\x1c\x02s\x00\x0fdpa-Zentralbild\x1c\x02\x05\x00\x0886540586\x1c\x02\x83\x00\tlandscape\x1c\x02x\x01uARCHIV\xc2\xa0- ILLUSTRATION - Eine Frau telefoniert am 16.12.2013 in Dresden (Sachsen) mit ihrem Mobiltelefon an der Wand zeichnet sich ihr Schatten ab. Beim Enkeltrick gaukeln Betr\xc3\xbcger ihren meist betagten Opfern am Telefon vor, ein naher Verwandter - etwa ein Enkel - zu sein. Foto: Arno Burgi/dpa (zu dpa vom 16.12.2016) Foto: Arno Burgi/dpa-Zentralbild +++ dpa-Bildfunk +++\x1c\x02(\x00\x00\x00'}, 'icc_profile': b'\x00\x00\x0cHLino\x02\x10\x00\x00mntrRGB XYZ \x07\xce\x00\x02\x00\t\x00\x06\x001\x00\x00acspMSFT\x00\x00\x00\x00IEC sRGB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf6\xd6\x00\x01\x00\x00\x00\x00\xd3-HP  \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x11cprt\x00\x00\x01P\x00\x00\x003desc\x00\x00\x01\x84\x00\x00\x00lwtpt\x00\x00\x01\xf0\x00\x00\x00\x14bkpt\x00\x00\x02\x04\x00\x00\x00\x14rXYZ\x00\x00\x02\x18\x00\x00\x00\x14gXYZ\x00\x00\x02,\x00\x00\x00\x14bXYZ\x00\x00\x02@\x00\x00\x00\x14dmnd\x00\x00\x02T\x00\x00\x00pdmdd\x00\x00\x02\xc4\x00\x00\x00\x88vued\x00\x00\x03L\x00\x00\x00\x86view\x00\x00\x03\xd4\x00\x00\x00$lumi\x00\x00\x03\xf8\x00\x00\x00\x14meas\x00\x00\x04\x0c\x00\x00\x00$tech\x00\x00\x040\x00\x00\x00\x0crTRC\x00\x00\x04<\x00\x00\x08\x0cgTRC\x00\x00\x04<\x00\x00\x08\x0cbTRC\x00\x00\x04<\x00\x00\x08\x0ctext\x00\x00\x00\x00Copyright (c) 1998 Hewlett-Packard Company\x00\x00desc\x00\x00\x00\x00\x00\x00\x00\x12sRGB IEC61966-2.1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x12sRGB IEC61966-2.1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00XYZ \x00\x00\x00\x00\x00\x00\xf3Q\x00\x01\x00\x00\x00\x01\x16\xccXYZ \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00XYZ \x00\x00\x00\x00\x00\x00o\xa2\x00\x008\xf5\x00\x00\x03\x90XYZ \x00\x00\x00\x00\x00\x00b\x99\x00\x00\xb7\x85\x00\x00\x18\xdaXYZ \x00\x00\x00\x00\x00\x00$\xa0\x00\x00\x0f\x84\x00\x00\xb6\xcfdesc\x00\x00\x00\x00\x00\x00\x00\x16IEC http://www.iec.ch\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x16IEC http://www.iec.ch\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00desc\x00\x00\x00\x00\x00\x00\x00.IEC 61966-2.1 Default RGB colour space - sRGB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00.IEC 61966-2.1 Default RGB colour space - sRGB\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00desc\x00\x00\x00\x00\x00\x00\x00,Reference Viewing Condition in IEC61966-2.1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00,Reference Viewing Condition in IEC61966-2.1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00view\x00\x00\x00\x00\x00\x13\xa4\xfe\x00\x14_.\x00\x10\xcf\x14\x00\x03\xed\xcc\x00\x04\x13\x0b\x00\x03\\\x9e\x00\x00\x00\x01XYZ \x00\x00\x00\x00\x00L\tV\x00P\x00\x00\x00W\x1f\xe7meas\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x8f\x00\x00\x00\x02sig \x00\x00\x00\x00CRT curv\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x00\x05\x00\n\x00\x0f\x00\x14\x00\x19\x00\x1e\x00#\x00(\x00-\x002\x007\x00;\x00@\x00E\x00J\x00O\x00T\x00Y\x00^\x00c\x00h\x00m\x00r\x00w\x00|\x00\x81\x00\x86\x00\x8b\x00\x90\x00\x95\x00\x9a\x00\x9f\x00\xa4\x00\xa9\x00\xae\x00\xb2\x00\xb7\x00\xbc\x00\xc1\x00\xc6\x00\xcb\x00\xd0\x00\xd5\x00\xdb\x00\xe0\x00\xe5\x00\xeb\x00\xf0\x00\xf6\x00\xfb\x01\x01\x01\x07\x01\r\x01\x13\x01\x19\x01\x1f\x01%\x01+\x012\x018\x01>\x01E\x01L\x01R\x01Y\x01`\x01g\x01n\x01u\x01|\x01\x83\x01\x8b\x01\x92\x01\x9a\x01\xa1\x01\xa9\x01\xb1\x01\xb9\x01\xc1\x01\xc9\x01\xd1\x01\xd9\x01\xe1\x01\xe9\x01\xf2\x01\xfa\x02\x03\x02\x0c\x02\x14\x02\x1d\x02&\x02/\x028\x02A\x02K\x02T\x02]\x02g\x02q\x02z\x02\x84\x02\x8e\x02\x98\x02\xa2\x02\xac\x02\xb6\x02\xc1\x02\xcb\x02\xd5\x02\xe0\x02\xeb\x02\xf5\x03\x00\x03\x0b\x03\x16\x03!\x03-\x038\x03C\x03O\x03Z\x03f\x03r\x03~\x03\x8a\x03\x96\x03\xa2\x03\xae\x03\xba\x03\xc7\x03\xd3\x03\xe0\x03\xec\x03\xf9\x04\x06\x04\x13\x04 \x04-\x04;\x04H\x04U\x04c\x04q\x04~\x04\x8c\x04\x9a\x04\xa8\x04\xb6\x04\xc4\x04\xd3\x04\xe1\x04\xf0\x04\xfe\x05\r\x05\x1c\x05+\x05:\x05I\x05X\x05g\x05w\x05\x86\x05\x96\x05\xa6\x05\xb5\x05\xc5\x05\xd5\x05\xe5\x05\xf6\x06\x06\x06\x16\x06\'\x067\x06H\x06Y\x06j\x06{\x06\x8c\x06\x9d\x06\xaf\x06\xc0\x06\xd1\x06\xe3\x06\xf5\x07\x07\x07\x19\x07+\x07=\x07O\x07a\x07t\x07\x86\x07\x99\x07\xac\x07\xbf\x07\xd2\x07\xe5\x07\xf8\x08\x0b\x08\x1f\x082\x08F\x08Z\x08n\x08\x82\x08\x96\x08\xaa\x08\xbe\x08\xd2\x08\xe7\x08\xfb\t\x10\t%\t:\tO\td\ty\t\x8f\t\xa4\t\xba\t\xcf\t\xe5\t\xfb\n\x11\n\'\n=\nT\nj\n\x81\n\x98\n\xae\n\xc5\n\xdc\n\xf3\x0b\x0b\x0b"\x0b9\x0bQ\x0bi\x0b\x80\x0b\x98\x0b\xb0\x0b\xc8\x0b\xe1\x0b\xf9\x0c\x12\x0c*\x0cC\x0c\\\x0cu\x0c\x8e\x0c\xa7\x0c\xc0\x0c\xd9\x0c\xf3\r\r\r&\r@\rZ\rt\r\x8e\r\xa9\r\xc3\r\xde\r\xf8\x0e\x13\x0e.\x0eI\x0ed\x0e\x7f\x0e\x9b\x0e\xb6\x0e\xd2\x0e\xee\x0f\t\x0f%\x0fA\x0f^\x0fz\x0f\x96\x0f\xb3\x0f\xcf\x0f\xec\x10\t\x10&\x10C\x10a\x10~\x10\x9b\x10\xb9\x10\xd7\x10\xf5\x11\x13\x111\x11O\x11m\x11\x8c\x11\xaa\x11\xc9\x11\xe8\x12\x07\x12&\x12E\x12d\x12\x84\x12\xa3\x12\xc3\x12\xe3\x13\x03\x13#\x13C\x13c\x13\x83\x13\xa4\x13\xc5\x13\xe5\x14\x06\x14\'\x14I\x14j\x14\x8b\x14\xad\x14\xce\x14\xf0\x15\x12\x154\x15V\x15x\x15\x9b\x15\xbd\x15\xe0\x16\x03\x16&\x16I\x16l\x16\x8f\x16\xb2\x16\xd6\x16\xfa\x17\x1d\x17A\x17e\x17\x89\x17\xae\x17\xd2\x17\xf7\x18\x1b\x18@\x18e\x18\x8a\x18\xaf\x18\xd5\x18\xfa\x19 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\xee\xb4\xef@\xef\xcc\xf0X\xf0\xe5\xf1r\xf1\xff\xf2\x8c\xf3\x19\xf3\xa7\xf44\xf4\xc2\xf5P\xf5\xde\xf6m\xf6\xfb\xf7\x8a\xf8\x19\xf8\xa8\xf98\xf9\xc7\xfaW\xfa\xe7\xfbw\xfc\x07\xfc\x98\xfd)\xfd\xba\xfeK\xfe\xdc\xffm\xff\xff'}
```

Due to confidentiality reasons, I can not provide the image that I'm trying to process. However, I will provide the anonomised XMP metadata of the image that causes the error (`filename_example_1.jpg`) and one which doesn't cause an error (`filename_example_2.jpg`). This XMP metadata was extracted using https://www.imgonline.com.ua/. This shows that the metadata is present for both the working and the erroneous files.

`filename_example_1.jpg` (erroneous): 
- About: Anonymous
- City: Anonymous
- State: Anonymous
- Country: Anonymous
- Credit: Anonymous
- Source: Anonymous
- Caption Writer: Anonymous
- Headline: Anonymous
- Create Date: Anonymous
- Marked: True
- Creator: Anonymous
- Subject: Anonymous
- Description: Anonymous
- Rights: Anonymous
- Title: 86540586
- Country Code: Anonymous
- Creator Contact Info: Anonymous

`filename_example_2.jpg` (successfully loaded by Pillow): 
- Metadata Date: Anonymous
- Rating: 0 
- Format: image/jpeg
- Subject: Anonymous
- Description: Anonymous
- Creator: Anonymous
- Rights: Anonymous
- Lens: EF70-200mm f/4L USM
- Image Number: 0
- Approximate Focus Distance: 4294967295
- Flash Compensation: 0
- Firmware: 1.3.3
- Color Mode: RGB
- ICC Profile Name: sRGB IEC61966-2. 1
- City: Anonymous
- State: Anonymous
- Country: Anonymous
- Category: SPO
- Credit: Anonymous
- Source: Anonymous
- Headline: Anonymous
- Date Created: Anonymous
- Document ID: Anonymous
- Instance ID: Anonymous
- Original Document ID: Anonymous
- History Action: saved, saved 
- History Instance ID: Anonymous
- History When: Anonymous
- History Sofware Agent: Anonymous
- History Changed: /, /
- Marked: True
- Prefs: Tagged:0, ColorClass:0, Rating: 0, FrameNum:00115
- PM Version: PM4
- Country Code: Anonymous
- Location: Anonymous

If anyone is able to provide some insights into this bug, please let me know!



Discussion:

Resolving patch:
diff --git a/src/PIL/Image.py b/src/PIL/Image.py
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -1385,7 +1385,7 @@ def getextrema(self):
 
     def _getxmp(self, xmp_tags):
         def get_name(tag):
-            return tag.split("}")[1]
+            return re.sub("^{[^}]+}", "", tag)
 
         def get_value(element):
             value = {get_name(k): v for k, v in element.attrib.items()}
diff --git a/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py
--- a/src/PIL/JpegImagePlugin.py
+++ b/src/PIL/JpegImagePlugin.py
@@ -496,7 +496,7 @@ def getxmp(self):
 
         for segment, content in self.applist:
             if segment == "APP1":
-                marker, xmp_tags = content.rsplit(b"\x00", 1)
+                marker, xmp_tags = content.split(b"\x00")[:2]
                 if marker == b"http://ns.adobe.com/xap/1.0/":
                     return self._getxmp(xmp_tags)
         return {}


Test patch:
diff --git a/Tests/images/xmp_no_prefix.jpg b/Tests/images/xmp_no_prefix.jpg
new file mode 100644
Binary files /dev/null and b/Tests/images/xmp_no_prefix.jpg differ
diff --git a/Tests/images/xmp_padded.jpg b/Tests/images/xmp_padded.jpg
new file mode 100644
Binary files /dev/null and b/Tests/images/xmp_padded.jpg differ
diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py
--- a/Tests/test_file_jpeg.py
+++ b/Tests/test_file_jpeg.py
@@ -882,7 +882,10 @@ def read(n=-1):
     def test_getxmp(self):
         with Image.open("Tests/images/xmp_test.jpg") as im:
             if ElementTree is None:
-                with pytest.warns(UserWarning):
+                with pytest.warns(
+                    UserWarning,
+                    match="XMP data cannot be read without defusedxml dependency",
+                ):
                     assert im.getxmp() == {}
             else:
                 xmp = im.getxmp()
@@ -905,6 +908,28 @@ def test_getxmp(self):
             with Image.open("Tests/images/hopper.jpg") as im:
                 assert im.getxmp() == {}
 
+    def test_getxmp_no_prefix(self):
+        with Image.open("Tests/images/xmp_no_prefix.jpg") as im:
+            if ElementTree is None:
+                with pytest.warns(
+                    UserWarning,
+                    match="XMP data cannot be read without defusedxml dependency",
+                ):
+                    assert im.getxmp() == {}
+            else:
+                assert im.getxmp() == {"xmpmeta": {"key": "value"}}
+
+    def test_getxmp_padded(self):
+        with Image.open("Tests/images/xmp_padded.jpg") as im:
+            if ElementTree is None:
+                with pytest.warns(
+                    UserWarning,
+                    match="XMP data cannot be read without defusedxml dependency",
+                ):
+                    assert im.getxmp() == {}
+            else:
+                assert im.getxmp() == {"xmpmeta": None}
+
     @pytest.mark.timeout(timeout=1)
     def test_eof(self):
         # Even though this decoder never says that it is finished
diff --git a/Tests/test_file_png.py b/Tests/test_file_png.py
--- a/Tests/test_file_png.py
+++ b/Tests/test_file_png.py
@@ -665,7 +665,10 @@ def test_plte_length(self, tmp_path):
     def test_getxmp(self):
         with Image.open("Tests/images/color_snakes.png") as im:
             if ElementTree is None:
-                with pytest.warns(UserWarning):
+                with pytest.warns(
+                    UserWarning,
+                    match="XMP data cannot be read without defusedxml dependency",
+                ):
                     assert im.getxmp() == {}
             else:
                 xmp = im.getxmp()
diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py
--- a/Tests/test_file_tiff.py
+++ b/Tests/test_file_tiff.py
@@ -734,7 +734,10 @@ def test_discard_icc_profile(self, tmp_path):
     def test_getxmp(self):
         with Image.open("Tests/images/lab.tif") as im:
             if ElementTree is None:
-                with pytest.warns(UserWarning):
+                with pytest.warns(
+                    UserWarning,
+                    match="XMP data cannot be read without defusedxml dependency",
+                ):
                     assert im.getxmp() == {}
             else:
                 xmp = im.getxmp()
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
@@ -118,7 +118,10 @@ def test_getxmp():
 
     with Image.open("Tests/images/flower2.webp") as im:
         if ElementTree is None:
-            with pytest.warns(UserWarning):
+            with pytest.warns(
+                UserWarning,
+                match="XMP data cannot be read without defusedxml dependency",
+            ):
                 assert im.getxmp() == {}
         else:
             assert (