-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix: improve image URL parsing robustness across providers #8383
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
base: main
Are you sure you want to change the base?
Conversation
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.
1 issue found across 7 files
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="core/llm/llms/Ollama.ts">
<violation number="1" location="core/llm/llms/Ollama.ts:308">
Calling extractBase64FromDataUrl here will throw on malformed data URLs and bubble up, regressing the previous behavior that tolerated bad input; wrap this in error handling or preserve the non-throwing fallback so malformed URLs don’t crash message conversion.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
| if (part.type === "imageUrl" && part.imageUrl) { | ||
| const image = part.imageUrl?.url.split(",").at(-1); | ||
| const image = part.imageUrl?.url | ||
| ? extractBase64FromDataUrl(part.imageUrl.url) |
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.
Calling extractBase64FromDataUrl here will throw on malformed data URLs and bubble up, regressing the previous behavior that tolerated bad input; wrap this in error handling or preserve the non-throwing fallback so malformed URLs don’t crash message conversion.
Prompt for AI agents
Address the following comment on core/llm/llms/Ollama.ts at line 308:
<comment>Calling extractBase64FromDataUrl here will throw on malformed data URLs and bubble up, regressing the previous behavior that tolerated bad input; wrap this in error handling or preserve the non-throwing fallback so malformed URLs don’t crash message conversion.</comment>
<file context>
@@ -303,7 +304,9 @@ class Ollama extends BaseLLM implements ModelInstaller {
if (part.type === "imageUrl" && part.imageUrl) {
- const image = part.imageUrl?.url.split(",").at(-1);
+ const image = part.imageUrl?.url
+ ? extractBase64FromDataUrl(part.imageUrl.url)
+ : undefined;
if (image) {
</file context>
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.
The extractBase64FromDataUrl function now returns undefined instead of throwing on malformed URLs
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.
Thanks for the feedback! I've saved this as a new learning to improve future reviews.
RomneyDa
left a comment
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.
@dcs-soni looks like some tests are failing and see cubic feedback!
92ee1ac to
64f3e12
Compare
Description
Handle malformed data URLs in Bedrock, Anthropic, Gemini, and Ollama adapters. Currently, they use unsafe array destructuring when parsing data URLs, causing runtime crashes on malformed input or unexpected results even if the parsed data is not correct base64.
Data URLs can be malformed due to various reasons, like, copy/paste from applications generating invalid URLs, user provided code containing malformed base64 URLs or maybe a network connection during image uploads.
This fix:
AI Code Review
@continue-reviewChecklist
Screen recording or screenshot
[ When applicable, please include a short screen recording or screenshot - this makes it much easier for us as contributors to review and understand your changes. See this PR as a good example. ]
Tests
[ What tests were added or updated to ensure the changes work as expected? ]
Summary by cubic
Improved image data URL parsing across providers to prevent crashes on malformed inputs. Centralizes parsing logic and adds safer base64 extraction and MIME type handling.
Written for commit 64f3e12. Summary will update automatically on new commits.