Remove zero-byte end padding when parsing any XMP data by radarhere · Pull Request #8171 · python-pillow/Pillow

@radarhere

@radarhere

@bigcat88

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
Maybe here should be a check for that? Should I create a separate issue for that?

@bigcat88

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 image.info dictionary

@radarhere

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!