anomalyco / anomalyco/opencode
Bedrock event-stream framing buffers without bound when a frame prelude declares an oversized length
@rekram1-node is already working on this.
Since Aug 24, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
packages/llm/src/protocols/bedrock-event-stream.ts reads total_length from the 4-byte frame prelude and breaks out of the decode loop until that many bytes have arrived. total_length is a 32-bit field, so a malformed or truncated response can declare up to 4 GiB. Nothing bounds the wait: appendChunk keeps appending, and because the buffer is only compacted once a frame completes, it re-copies the whole accumulated window on every network chunk.
Cost is quadratic in bytes received. Feeding bytes after a prelude declaring 0xFFFFFFFF, in 16 KiB chunks:
| sent | wall | RSS |
|---|---|---|
| 8 MiB | 1.2 s | 134 MiB |
| 16 MiB | 4.1 s | 166 MiB |
| 32 MiB | 10.9 s | 262 MiB |
| 64 MiB | 47.2 s | 650 MiB |
AWS documents a 16 MiB maximum event-stream message; @smithy/eventstream-codec does not enforce it, and neither do we. The stream also surfaces no useful error — it ends with the generic Provider stream ended without a terminal finish event after buffering everything.
Reachable from any configured Bedrock-compatible baseURL (gateway, proxy, self-hosted relay) that returns a malformed body.
Expected: reject a frame whose declared length exceeds the protocol maximum instead of buffering toward a frame that can never complete.
Happy to send a PR — the check is one comparison before the existing length gate.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.