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
decode_base64_to_image: don't crash if EXIF data is broken #4764
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-4764-all-demos |
Hi @akx we definitely need an example image or some other way to reproduce this, and a test to ensure that we don't have a regression in the future |
@abidlabs Guess I'll close this then 👍 |
@abidlabs Reopened, since I figured out a reliable repro 😁 |
a971679
to
bf840d0
Compare
@@ -55,10 +57,15 @@ def extract_base64_data(x: str) -> str: | |||
def decode_base64_to_image(encoding: str) -> Image.Image: | |||
image_encoded = extract_base64_data(encoding) | |||
img = Image.open(BytesIO(base64.b64decode(image_encoded))) | |||
exif = img.getexif() | |||
# 274 is the code for image rotation and 1 means "correct orientation" | |||
if exif.get(274, 1) != 1 and hasattr(ImageOps, "exif_transpose"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we remove this check exif.get(274, 1) != 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the commit message implies, exif_transpose
does it by itself.
Thanks @akx tested and LGTM. Will merge in after CI runs |
Description
This adds a simple guard for
decode_base64_to_image
to not just throw when transposing the image fails.I can't share the file that causes this issue, but the traceback is
🎯 PRs Should Target Issues
This PR doesn't target an issue right now. If you like, I can open an issue that says the above.