-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Some image urls don't load after #5324 #5341
Comments
Thank you for well documenting examples that break after the last PR. I should have had stronger wording and concerns in my PR about the stricter checks, and I agree that this scenario is common enough that something should be done to loosen the bounds further. However, I'm not sure this leaves anything except removing errors on unknown extensions and unknown MIMEs entirely and relying solely on magic bytes with I think this is okay, since as you mentioned, this is already being done after loading some bytes as it is now. But of course now we always would have to load bytes before rejecting an image. We could also expand the trait to formally check for magic bytes with all loaders to allow the same weaker support checking and scrap MIME/URI on those too. |
In my opinion that's fine trade-off, if it means loading images from an url is more likely to succeed.
Since the image loaders call |
The magic bytes that |
I was thinking along the lines of adding |
Describe the bug
#5324 introduced stricter image uri and mime detection. While this makes sense for e.g. file urls where the extensions are likely correct, I don't think we should check extensions for http urls, as they are not reliable at all.
Some imaginary cases I can think of where the new checks would break:
Some of these cases might be bad api design. If you have full control over the backend that might not be a problem but if you e.g. build a chat app where people can send an image url and the app tries to load the image preview from the external url, you would want to support as many urls as possible.
We could try stripping the query params and fragments when checking for the extensions, but I don't think the extra complexity is worth it, considering that this is optimizing the failure case.
The mime check is probably more reliable, but might not always be true. When uploading an image to s3 and you forget to set the mime type, it will have
application/octet-stream
. I believe, when showing such an image in a<img>
tag, the browser will still show it successfully (but I'm not 100% sure).Since we already have the image downloaded when checking the mime type, we might as well just get the type via
image::guess_format
.Also, we aren't even using the mime type when loading the image, instead relying on the image crate to guess the format, meaning currently
image
has to guess the type twice (once when we call 'image::guess_type' and once more when we actually decode the image).I think we should at least make this behavior configurable, and turn it off by default.
To Reproduce
Steps to reproduce the behavior:
cargo run -p egui_demo_app --features image_viewer
from the egui repo on the current masterExpected behavior
Images should load, no matter the url
Additional context
relevant pr: #5324
The text was updated successfully, but these errors were encountered: