Remove zero-byte end padding when parsing any XMP data#8171
Remove zero-byte end padding when parsing any XMP data#8171hugovk merged 1 commit intopython-pillow:mainfrom
Conversation
|
Yes, with this changes all will be good. However I found another place in Pillow that failing my tests and I think we need to take a look at that: ImageOps.py , exif_transpose: exif_image.info["xmp"] = re.sub(
pattern.encode(), b"", exif_image.info["xmp"]
)I get an KeyError here, as "xmp" can be not present in exif_image.info keys |
|
ImageOps.py , exif_transpose: elif "XML:com.adobe.xmp" in exif_image.info:
for pattern in (
r'tiff:Orientation="([0-9])"',
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
):
exif_image.info["XML:com.adobe.xmp"] = re.sub(
pattern, "", exif_image.info["XML:com.adobe.xmp"]
)
elif "xmp" in exif_image.info:
for pattern in (
r'tiff:Orientation="([0-9])"',
r"<tiff:Orientation>([0-9])</tiff:Orientation>",
):
exif_image.info["xmp"] = re.sub(
pattern.encode(), b"", exif_image.info["xmp"]
)imho, this will be the correct code that not fails with exception when "xmp" not in |
|
I imagine this is where the failure is occurring? For my own clarity, I wouldn't say that pillow-heif is failing, but rather Pillow is failing to handle an image you've constructed in your tests. But there's no reason that your constructed image isn't perfectly valid, so I've created #8173 By the way, thanks for letting us know about these matters before the release has gone out! |
Last year, we received a report of a JPEG image where XMP data was zero-padded at the end. I created a fix for that by adjusting JpegImagePlugin.
Now #8069 (comment) reports that XMP data might also be zero-padded for another format.
So this PR removes zero-byte end padding from XMP data for all formats, not just JPEG.