Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove zero-byte end padding when parsing any XMP data #8171

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

radarhere
Copy link
Member

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.

@bigcat88
Copy link
Contributor

bigcat88 commented Jun 26, 2024

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
Copy link
Contributor

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
Copy link
Member Author

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!

@hugovk hugovk merged commit 6a44854 into python-pillow:main Jun 27, 2024
55 of 56 checks passed
@radarhere radarhere deleted the xmp branch June 27, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants