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

XMP containing invalid bytes leading fail to decode image #69

Closed
eeyrw opened this issue Jan 21, 2023 · 4 comments
Closed

XMP containing invalid bytes leading fail to decode image #69

eeyrw opened this issue Jan 21, 2023 · 4 comments
Labels
bug Something isn't working fixed Fixed in last version

Comments

@eeyrw
Copy link

eeyrw commented Jan 21, 2023

Describe the bug

Fail to decode image just because of some invalid bytes in XMP.

Steps/Code to Reproduce

from PIL import Image
from pillow_heif import register_heif_opener

register_heif_opener()

im = Image.open("images/input.heic")  # do whatever need with a Pillow image

input.heic: https://easyupload.io/2p5p0d

Expected Results

No error is thrown or warning prompt.

Actual Results

image

Versions

3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)]
Windows-10-10.0.19041-SP0
0.9.2
{'version': {'libheif': '1.14.2', 'x265': 'x265 HEVC encoder (3.4+31-6722fce1f)', 'aom': 'AOMedia Project AV1 Encoder v3.5.0'}, 'decoders': {'HEVC': 1, 'AV1': 1, 'AVC': 0}, 'encoders': {'HEVC': 1, 'AV1': 1, 'AVC': 0}}
@bigcat88 bigcat88 added the bug Something isn't working label Jan 21, 2023
@bigcat88
Copy link
Owner

bigcat88 commented Jan 21, 2023

Hm, this is a valid XMP but me just forgot that maybe will be case when last byte can be zero.
I will add test & fix for this and will publish a hotfix release within 36 hours.

Thanks for replying this!

Added:
After closer look at sample, I see two bugs.

  1. Zero byte at the end of XMP
  2. XMP encoding is latin1

I will wrap decode in try handler and in case of exception during decoding will use latin1 to decode.
As defusedxml do not support data in latin1 encoding, XMP data in this case will be converted to utf-8.
After resaving file with such XMP data, it will be a bit differ in raw comparison(as string it should be equal, but not when comparing as bytes)

bigcat88 added a commit that referenced this issue Jan 21, 2023
@bigcat88 bigcat88 added the fixed in upcoming release fix will arrive with next release label Jan 21, 2023
@eeyrw
Copy link
Author

eeyrw commented Jan 22, 2023

Hm, this is a valid XMP but me just forgot that maybe will be case when last byte can be zero. I will add test & fix for this and will publish a hotfix release within 36 hours.

Thanks for replying this!

Added: After closer look at sample, I see two bugs.

  1. Zero byte at the end of XMP
  2. XMP encoding is latin1

I will wrap decode in try handler and in case of exception during decoding will use latin1 to decode. As defusedxml do not support data in latin1 encoding, XMP data in this case will be converted to utf-8. After resaving file with such XMP data, it will be a bit differ in raw comparison(as string it should be equal, but not when comparing as bytes)

String encoding is always the trouble... There are so many local encodings and hard to identify.

@bigcat88 bigcat88 added fixed Fixed in last version and removed fixed in upcoming release fix will arrive with next release labels Jan 22, 2023
@bigcat88
Copy link
Owner

Yeah, but not so many encodings can be used to encode XMP and latin1 encoding has no invalid bytes, so now it is fine.

@bigcat88
Copy link
Owner

@eeyrw can we close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed Fixed in last version
Projects
None yet
Development

No branches or pull requests

2 participants