From 2488167f33b7e357315c7052273b973fe2cad8e8 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 10 Jul 2023 22:00:30 +1000 Subject: [PATCH] Allow for zero-byte padding at end of XMP data --- Tests/images/xmp_padded.jpg | Bin 0 -> 778 bytes Tests/test_file_jpeg.py | 8 ++++++++ src/PIL/JpegImagePlugin.py | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 Tests/images/xmp_padded.jpg diff --git a/Tests/images/xmp_padded.jpg b/Tests/images/xmp_padded.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9ecfb3efebed10b67eb90a997088c52bb76762b2 GIT binary patch literal 778 zcmex=s)|yBtNcQetFn_V zQ_WTR(nVgxdTk&}~?hnq)&msi3_QAW{-Wbpq0gCGYeoR}Gv7?=bZnFSgD zA7PLO1|2IS7%)HqBNHRO;Y1B)Q5kfNa@ zn{Z$vyHcTuQRBpg9Li1`4~hm|{Gei-RMf=DB_=K*DW$5WuA!-AVrph?VQJ;;;_Bw^ z;pr6|5*ijB5gC=7lA4yDk(pIoQd(ACQCZd8(%RPE(b+X=@|3C5rq7r;YtiB*OP4KQ zv2xX>&0Dr^+rDGxu0w~996fgY#K}{aE?>EN?fQ+Iw;n!v{N(Ag=PzEq`uOSdm#^Qx z|M>X}Pb?HxGHT=y zahkYr<3UbkKb$@|Xn~>=}Ok L>(W@j|NkZcQRV=4 literal 0 HcmV?d00001 diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index 0247527f5..904fecebf 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -898,6 +898,14 @@ class TestFileJpeg: with Image.open("Tests/images/hopper.jpg") as im: assert im.getxmp() == {} + def test_getxmp_padded(self): + with Image.open("Tests/images/xmp_padded.jpg") as im: + if ElementTree is None: + with pytest.warns(UserWarning): + 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/src/PIL/JpegImagePlugin.py b/src/PIL/JpegImagePlugin.py index dfc7e6e9f..a28cd0367 100644 --- a/src/PIL/JpegImagePlugin.py +++ b/src/PIL/JpegImagePlugin.py @@ -496,7 +496,7 @@ class JpegImageFile(ImageFile.ImageFile): 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 {}