Skip to content

Parse XMP tag bytes without decoding to string #8960

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented May 15, 2025

Resolves #8957

The issue has found that XMP tag bytes may contain non-ascii bytes. This raises an error when trying to parse them to get the orientation.

Pillow/src/PIL/Image.py

Lines 1541 to 1544 in 3c71559

if not xmp_tags and (xmp_tags := self.info.get("xmp")):
xmp_tags = xmp_tags.decode("utf-8")
if xmp_tags:
match = re.search(r'tiff:Orientation(="|>)([0-9])', xmp_tags)

Instead of changing the XMP tag bytes to a string to match the pattern, this PR changes the pattern to bytes to match the XMP tag bytes.

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.

Image.getexif() errors on n04532106_1553.JPEG from ImageNet
1 participant