Skip to content

fix: handle invalid image payloads from Read tool#15262

Open
LIU9293 wants to merge 2 commits intoanomalyco:devfrom
LIU9293:fix/read-invalid-image-data
Open

fix: handle invalid image payloads from Read tool#15262
LIU9293 wants to merge 2 commits intoanomalyco:devfrom
LIU9293:fix/read-invalid-image-data

Conversation

@LIU9293
Copy link

@LIU9293 LIU9293 commented Feb 26, 2026

Issue for this PR

Closes #15264

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A malformed image attachment from Read could reach the provider as an image/file part and trigger a hard provider error ("image data does not represent a valid image"), which then caused follow-up turns to keep failing in the same session.

This PR validates image payloads before provider send:

  • checks base64 shape for data URLs
  • checks image signatures for png/jpeg/gif/webp
  • applies to both image parts and file parts carrying image media (data or data-url url)
  • downgrades invalid payloads to a safe text error message so the session continues

Also adds regression tests for invalid base64 image parts and invalid image file data.

How did you verify your code works?

  • Ran bun test test/provider/transform.test.ts in packages/opencode
  • Added and ran regression tests covering:
    • invalid base64 in image part
    • invalid bytes in image file part
  • Ran bun run typecheck in packages/opencode

Screenshots / recordings

N/A (non-UI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Feb 26, 2026
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR that might be addressing similar image handling concerns:

Related PR:

This PR also deals with image handling in the Read tool context, though it focuses on file extension casing rather than payload validation. It might be worth checking if there's any overlap in scope.

The current PR (#15262) appears to be unique in its focus on validating image payloads with binary signature checks and base64 sanity checks before provider submission - a more comprehensive validation approach than what I found in the search results.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 26, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@LIU9293 LIU9293 force-pushed the fix/read-invalid-image-data branch from ef7d530 to 73e6ff5 Compare February 26, 2026 17:08
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.

Read: invalid image payload from file attachment poisons subsequent turns

1 participant