Skip to content

Conversation

dcs-soni
Copy link

@dcs-soni dcs-soni commented Sep 29, 2025

I have read the CLA Document and I hereby sign the CLA

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:

  • Prevents runtime crashes on malformed image data.
  • Improves error handling and user experience.
  • Improved response from the providers if the image URLs are malformed.

AI Code Review

  • Team members only: AI review runs automatically when PR is opened or marked ready for review
  • Team members can also trigger a review by commenting @continue-review

Checklist

  • I've read the contributing guide
  • [] The relevant docs, if any, have been updated or created
  • [] The relevant tests, if any, have been updated or created

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

Improves image data URL parsing across Anthropic, Bedrock, Gemini, and Ollama to prevent crashes on malformed input and return clearer errors.

  • Bug Fixes
    • Validate the comma separator in data URLs and throw a descriptive error if missing.
    • Extract base64 by joining all parts after the first comma to avoid unsafe array destructuring.
    • Apply consistent parsing in both core LLM implementations and OpenAI adapter APIs (Anthropic, Bedrock).

@dcs-soni dcs-soni requested a review from a team as a code owner September 29, 2025 13:35
@dcs-soni dcs-soni requested review from Patrick-Erichsen and removed request for a team September 29, 2025 13:35
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Sep 29, 2025
Copy link


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

@dcs-soni
Copy link
Author

recheck

Copy link
Collaborator

@Patrick-Erichsen Patrick-Erichsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! Logic looks good but lets pull this out into a common util somewhere to prevent code duplication

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Oct 1, 2025
@dcs-soni dcs-soni force-pushed the fix/robust-image-url-parsing branch from 162d49a to 7e9055d Compare October 2, 2025 09:23
@dcs-soni
Copy link
Author

dcs-soni commented Oct 2, 2025

Thanks for the contribution! Logic looks good but lets pull this out into a common util somewhere to prevent code duplication

Thank you! Refactored, and I think moving the url parsing logic to core/util/url.ts would be a good idea here, or let me know if you'd prefer somewhere else?

@Patrick-Erichsen
Copy link
Collaborator

core/util/url.ts makes sense to me 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants