[BUG] Read tool on malformed image file causes unrecoverable session crash
Resolved 💬 4 comments Opened Feb 28, 2026 by yiidtw Closed Mar 28, 2026
Hi — thanks for the great tool. Ran into a reproducible crash scenario and traced the root cause; hope this helps.
What's Wrong?
Reading a file with an image extension (.png, .jpg) that contains invalid binary data crashes the session permanently. The error persists across --resume and /clear because the malformed payload is stored in conversation history.
Steps to Reproduce
Warning: This will crash the active session and --resume will not recover it. Test in a disposable session or use a subagent (Task tool) to isolate the impact.
python3 -c "
import os
with open('/tmp/corrupt.png', 'wb') as f:
f.write(b'\x89PNG\r\n\x1a\n' + os.urandom(2048))
"
Then in Claude Code: Read /tmp/corrupt.png. Session becomes unrecoverable.
Root Cause
- Read tool uses file extension to decide image handling →
.pngtriggers base64 path - Contents are base64-encoded and sent to API without validating image integrity
- Garbage bytes are interpreted as dimensions exceeding the 8000px API limit → 400 error
- Malformed payload is persisted in conversation history →
--resumereplays the same error - No recovery path: session is permanently broken
What Should Happen?
At minimum, fall back to text-mode (hex dump or error message) when image validation fails, rather than sending unvalidated content to the API and persisting it.
Related Issues
May share a root cause with #13480, #12351, #28485, #2939.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗