fix: IndexError in detect_media_type_from_base64 for non-base64 data …#5114
Open
Serjbory wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: IndexError in detect_media_type_from_base64 for non-base64 data …#5114Serjbory wants to merge 1 commit intomicrosoft:mainfrom
Serjbory wants to merge 1 commit intomicrosoft:mainfrom
Conversation
Author
|
@microsoft-github-policy-service agree |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: IndexError in detect_media_type_from_base64 for non-base64 data URIs
Motivation and Context
detect_media_type_from_base64(data_uri=...)raises an unhandledIndexErrorwhen the provided URI does not contain the;base64,separator (e.g.data:text/plain,Hello%20Worldor a plain HTTP URL). The function blindly callsdata_uri.split(";base64,", 1)[1]without first checking that the delimiter exists.The sister function
_get_data_bytes_as_strin the same file already guards against this case, butdetect_media_type_from_base64was missing the same check.Description
detect_media_type_from_base64that raises aValueError("Data URI must use base64 encoding.")whendata_uridoes not contain;base64,, consistent with the existing pattern in_get_data_bytes_as_str.test_data_content_detect_image_format_from_base64covering a non-base64 data URI (data:text/plain,Hello%20World) and a plain HTTP URL (http://example.com/image.png).Contribution Checklist