fix: bound read_file allocations — 32MB per-file cap + batch total limit#125
Merged
jamestexas merged 2 commits intomainfrom Mar 23, 2026
Merged
fix: bound read_file allocations — 32MB per-file cap + batch total limit#125jamestexas merged 2 commits intomainfrom
jamestexas merged 2 commits intomainfrom
Conversation
Adversarial tests prove both single-file and batch-read OOM vectors. Per-file reads over 32MB are rejected. Batch reads stop accumulating once total content exceeds 32MB, skipping remaining files. [mache-5c76b3]
There was a problem hiding this comment.
Pull request overview
This PR hardens the read_file MCP tool against unbounded memory usage by adding explicit per-file and batch-level size limits, with adversarial tests to prevent regressions.
Changes:
- Enforce a 32MB maximum size for single-file reads in
read_file. - Add a 32MB total-content cap for batch reads, returning per-file errors once the cap is hit.
- Add new tests covering oversized single-file reads and oversized batch totals.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| cmd/serve_handlers.go | Adds per-file size check and batch total-content limiting logic for read_file. |
| cmd/serve_test.go | Introduces adversarial tests validating oversized single-file rejection and batch total cap behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Pre-check ContentSize before reading to avoid allocate-then-reject - Clarify test comment re: handler allocation vs test setup allocation - Unmarshal batch results and assert structural invariants (succeeded > 0, exactly 1 cap trigger, skipped > 0, all paths accounted for) [mache-5c76b3]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Test plan
TestReadFile_RejectsOversizedContent— 64MB file rejectedTestReadFile_BatchRejectsTotalContentOverflow— 10×4MB batch caps at 32MBtask build+task testcleanCloses mache-5c76b3