Read tool: misidentified ICO file as PNG causes unrecoverable API error

Resolved 💬 3 comments Opened Apr 5, 2026 by tea-artist Closed Apr 5, 2026

Bug Description

When Claude Code's Read tool reads an image file, it infers media_type from the file extension rather than the actual file content (magic bytes). If a file has a .png extension but contains non-PNG data (e.g., an ICO file), the API rejects the request with a 400 error, and the conversation becomes permanently broken — every subsequent message replays the bad image block and crashes again.

Steps to Reproduce

  1. Have a file named something.png that is actually an ICO file (or any non-PNG format)
  2. Claude Code reads it with the Read tool (which supports reading images)
  3. The tool returns { type: "image", source: { type: "base64", media_type: "image/png", data: "<ICO base64>" } }
  4. The API rejects it: Image format image/png not supported
  5. Every subsequent message in the conversation also fails because the corrupted image block is part of the conversation history

Error Message

API Error: 400
{"error":{"message":"messages.5.content.37.image.source.base64.data: Image format image/png not supported"}}

Root Cause

The ICO file's base64 starts with AAABAAEAEBAAAAEAIABoBAAAFg... (ICO magic bytes: 00 00 01 00), but media_type is declared as image/png. The Anthropic API validates the actual content against the declared media type and rejects the mismatch.

Attached File

The problematic file: a 1,150-byte ICO file (16×16, 32bpp) named teable-logo.png.

Hex dump of first 16 bytes: 00 00 01 00 01 00 10 10 00 00 01 00 20 00 68 04

Base64 of the full file (for reproduction):

AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAABMLAAATCwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACKiopKioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqKSgAAAAAAAAAAAAAAAAAAAACKioqKioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKioYAAAAAAAAAAAAAAAAAgICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/AAAAAAAAAAAAAAAAioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKiv+Kior/AAAAAAAAAAAAAAAAioqK/4qKiv+Kior//////////////////////4qKiv+Kior/ioqK/4qKiv8AAAAAAAAAAAAAAAAAgICA/4CAgP+AgID////////////MzMz/gICA/4CAgP+AgID/gICA/4CAgP8AAAAAAAAAAAAAAACKior/ioqK/4qKiv///////////4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/wAAAAAAAAAAAAAAAACAgID/gICA/4CAgP//////gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/wAAAAAAAAAAAAAAAACKior/ioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKiv8AAAAAAAAAAAAAAACAgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP+AgID/gICA/4CAgP8AAAAAAAAAAAAAAAAAAAAAioqKioqKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKiv+Kior/ioqK/4qKioYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA//8AAP//AADgBwAAwAMAAMADAACAAwAAgAMAAIADAACAAwAAgAMAAIADAACAAwAAwAMAAOAHAAD//wAA//8AAA==

Expected Behavior

  1. Primary: Claude Code should detect the actual image format via magic bytes (file signature) instead of relying solely on the file extension, and set media_type accordingly. If the format is unsupported (e.g., ICO), it should either convert it or return a text error instead of an image block.
  1. Secondary: Even if an image block causes an API error, the conversation should not become permanently broken. Claude Code should be able to recover by stripping the problematic content block on retry.

Environment

  • Claude Code running in a Vercel sandbox
  • Model: claude-opus-4-6
  • The error reproduces identically across Anthropic direct API, AWS Bedrock, and Vertex AI — confirming it's a request-level issue, not provider-specific.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗