Repository navigation
Python: Decode Ollama inline image data before serialization - #9459
Jose Alvarez (jpalvarezl) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The focused validation change and regression coverage have no identified blocking issues; project tests were not run during this review.
0 open findings
What changed in this PR
This PR makes Ollama inline-image serialization unambiguous by decoding validated data URIs into bytes before passing them to Ollama.
Changes:
- Validate image data-URI structure and strictly decode base64 payloads.
- Add regression tests for valid images, malformed inputs, and path-shaped payloads without filesystem access.
| File | Description |
|---|---|
| python/packages/ollama/tests/test_ollama_chat_client.py | Adds validation and byte-backed serialization regression coverage. |
| python/packages/ollama/agent_framework_ollama/_chat_client.py | Validates inline image URIs and constructs byte-backed Ollama images. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: Findings reported
Scope: full PR (1 commit(s)): 1c7254981bb8
Model: gpt-5.6-sol
Overview
The change moves inline Ollama images to a strict, byte-backed data-URI conversion boundary, preventing the SDK from interpreting image strings as filesystem paths. The added tests cover canonical data URIs, malformed and path-shaped payloads, pre-dispatch rejection, and the absence of filesystem access. However, decoding every supplied image without count or size limits adds a process-memory exhaustion path before network dispatch.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
1 verified finding remained after source verification (1 medium) across 1 file. Details are attached to the affected lines below.
Affected areas: python/packages/ollama/agent_framework_ollama/_chat_client.py
Motivation & Context
Ollama inline image content is represented as a data URI, but the connector currently forwards the URI payload as a string. Because the Ollama image type supports multiple string semantics, the connector should decode inline content at its boundary so the image representation remains unambiguous and malformed inputs fail consistently.
Description & Review Guide
data:image/...;base64URI, strictly decode the payload, and pass an Ollama image backed by bytes. Add regression coverage for valid images, malformed POSIX/Windows/UNC/relative path-shaped payloads, and base64-shaped payloads, including assertions that path helpers are not invoked.ChatClientInvalidRequestExceptionbefore the Ollama request is sent.Related Issue
N/A - trivial change. This is a narrow correction that enforces the documented inline-image contract without changing valid input behavior.
AI Assistance
AI assistance details: Copilot assisted with the implementation, regression tests, and pull request description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.