Skip to content

fix(opencode): validate clipboard content type on Linux#23552

Open
h0wdee wants to merge 1 commit intoanomalyco:devfrom
h0wdee:fix/linux-clipboard-mime-validation-v2
Open

fix(opencode): validate clipboard content type on Linux#23552
h0wdee wants to merge 1 commit intoanomalyco:devfrom
h0wdee:fix/linux-clipboard-mime-validation-v2

Conversation

@h0wdee
Copy link
Copy Markdown

@h0wdee h0wdee commented Apr 20, 2026

Issue for this PR

Closes #23458

Type of change

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

What does this PR do?

On Linux, xclip -selection clipboard -t image/png -o outputs raw bytes even when clipboard contains text (not an image). The code only checked byteLength > 0, so text like ¯\_(ツ)_/¯ was incorrectly labeled as image/png and sent to the model, which failed with "could not process image".

This fix uses the existing sniffAttachmentMime() function to validate PNG magic bytes before treating clipboard content as an image. This is the same pattern used in the read tool.

How did you verify your code works?

  1. echo '¯\_(ツ)_/¯' | xclip -selection c
  2. Ctrl+V in OpenCode TUI
  3. Text now pastes correctly instead of failing with "could not process image"

Screenshots / recordings

N/A - not a UI change

Checklist

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

On Linux, xclip/wl-paste output raw bytes even when clipboard contains
text (not an image). The code only checked byteLength > 0, so text was
incorrectly labeled as image/png and sent to the model, which failed
with 'could not process image'.

Use existing sniffAttachmentMime() to validate PNG magic bytes before
returning clipboard content as an image.

Fixes anomalyco#23458
@github-actions
Copy link
Copy Markdown
Contributor

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

Based on my search, I found one potentially related PR:

Related PR:

However, #14552 appears to be a broader feature improvement for clipboard paste and drag-and-drop, while #23552 is a specific bug fix for validating mime types. They likely complement each other but are addressing different aspects of the clipboard functionality.

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.

[Bug]: Linux clipboard paste misidentifies text as image

1 participant