Skip to content

fix: handle incomplete and non-base64 image data URLs - #2413

Open
kevin9327 wants to merge 2 commits into
abetlen:mainfrom
kevin9327:fix-data-url-image-load
Open

kevin9327 wants to merge 2 commits into
abetlen:mainfrom
kevin9327:fix-data-url-image-load

Conversation

@kevin9327

Copy link
Copy Markdown

Summary

Both multimodal chat handlers loaded images with base64.b64decode(image_url.split(\",\")[1]). A data URL with no comma (for example data:image/png;base64) raised IndexError, and a non-base64 payload such as data:image/svg+xml,%3Csvg%3E was fed to b64decode.

A shared helper now splits on the first comma, decodes base64 when the header contains ;base64 (case-insensitive), unquotes plain data-URL payloads, and raises ValueError when the comma is missing.

Tests

tests/test_image_url.py covers a base64 round-trip, a ;BASE64 header, a missing comma, a percent-encoded SVG payload, and an HTTP URL (mocked).

_load_image used split(',')[1], so a data URL without a comma raised
IndexError, and non-base64 payloads such as data:image/svg+xml,<svg>
were passed to b64decode. Decode base64 when the header says so,
unquote plain payloads, and raise ValueError when the comma is missing.

This branch has not been deployed

No deployments
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.

1 participant