Skip to content

fix(transport): cap stdio line length#151

Open
SVilgelm wants to merge 1 commit into
rust-mcp-stack:mainfrom
SVilgelm:fix/stdio-line-cap
Open

fix(transport): cap stdio line length#151
SVilgelm wants to merge 1 commit into
rust-mcp-stack:mainfrom
SVilgelm:fix/stdio-line-cap

Conversation

@SVilgelm
Copy link
Copy Markdown
Contributor

📌 Summary

The stdio reader used AsyncBufReadExt::lines(), which buffers until a newline with no limit, so a peer streaming data without \n could force unbounded memory growth. Incoming lines are now capped; an over-long message is dropped (resynced to the next newline) and logged, keeping the stream alive.

🔍 Related Issues

✨ Changes Made

  • Replace lines() with a capped fill_buf/consume reader (4 MiB limit).
  • Drop and log lines exceeding the cap instead of buffering them.
  • Add unit tests for normal, trailing-newline-less, and oversized lines.

Replace the unbounded line reader with a capped reader (4 MiB) that drops over-long messages and resyncs, preventing unbounded buffering from a hostile peer.

Assisted-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Sergey Vilgelm <sergey@vilgelm.com>
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.

1 participant