Agent host: corrupt (7-byte) pasted-image attachment is persisted without validation and reproducibly crashes the renderer (SIGTRAP in image decode) on session open
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
Type: Bug
### Summary
Agent host sessions can persist a **truncated/corrupt pasted-image attachment** (7-byte file with a `.png` name), and rendering a session containing such an attachment **reproducibly crashes the renderer process with SIGTRAP** (EXC_BREAKPOINT — a Rust panic in Chromium's image decoding path). The user sees the window go blank with "reload window", losing all open editors' state. Four identical crashes over two days on my machine, all with byte-identical faulting stacks.
Two independent defects compound here:
1. **Write path (agent host)**: `AgentService._writeAndRewrite` (`src/vs/platform/agentHost/node/agentService.ts`) persists pasted-image bytes under `{userData}/agentSessionData/{sessionId}/attachments/{uuid}/{basename}` and immediately rewrites the message to reference the file — with **no size/magic-byte validation and no atomic write** (no temp-file + rename). When the source read races or fails partway (e.g. `resourceRead` from the client returns a short buffer during a reconnect), a 7-byte `.png` lands on disk and the session permanently references it. I have two such files from separate sessions (hex: `00 00 00 00 00 00 00`).
2. **Render path (workbench)**: rendering the session's request attachments (`chatListRenderer.ts` → image attachment cards) hands the corrupt bytes to Chromium's image decoder, which **panics (SIGTRAP) and takes down the whole renderer process** instead of failing the single image. The same session view crashes the renderer every time it is (re)opened until the corrupt file is removed from disk — which is exactly what made this hard to diagnose: the crash recurs on session open, not on any specific user action.
### Crash signature (4 identical instances)
```
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Faulting thread frames (Electron Framework, symbols approximate/stripped):
ares_dns_rr_get_ttl + … (nearest-symbol artifact)
rust_bmp$cxxbridge1$194$Reader$image_data_loaded ← Rust image decoder
v8::Isolate::NumberOfHeapSpaces()
```
Reports available on request: `Code Helper (Renderer)-2026-07-13-214821.ips`, `…-225113.ips`, `…-235705.ips`, `…-2026-07-14-105508.ips`. VS Code 1.128.0 (fc3def67), Electron node v24.17.0, macOS 26.5 arm64.
### Repro (with a corrupt file)
1. Create a session with a pasted image; locate its attachment under `~/Library/Application Support/Code/agentSessionData//attachments//`
2. Truncate the PNG: `printf '\0\0\0\0\0\0\0' > 粘贴的图像.png`
3. Reopen the session in the Agents window → renderer crashes (reload-window banner)
Removing the corrupt attachment directory stops the crashes.
### Suggested fixes
- **Write path**: validate before commit (non-empty, plausibly ≥ a few hundred bytes for an image contentType, magic bytes match the extension), write to a temp name and rename into place, and on failure keep the original attachment un-rewritten (the code already has that fallback for thrown errors — the gap is that a *short successful read* is not detected).
- **Render path**: image attachment cards should tolerate undecodable bytes (broken-image placeholder). A single bad file must not be able to kill the renderer; this is also a robustness issue for any on-disk corruption.
### Environment
- VS Code 1.128.0 stable (fc3def6774c7), macOS 26.5.1 arm64
- Agent host Claude sessions (local and remote SSH); attachments written by the local agent host
Contributor guide
Assessment
This issue has not been assessed yet.