Skip to content

fix(file): reject reads that do not fit the result buffer - #114

Closed
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-ed43
Closed

cursor[bot] wants to merge 1 commit into
mainfrom
cursor/high-severity-issues-ed43

Conversation

@cursor

@cursor cursor Bot commented Oct 10, 2026

Copy link
Copy Markdown

Bug and impact

file_read returned success after clipping a file to the caller buffer. agent_run passes a 4096-byte tool result slot. A workspace file of 4096 bytes or more (still under the 256 KiB hard cap) came back as a prefix with no error. A follow-up write_file replaces the whole file, so an edit such as "add a title to notes.md" on an 8 KiB note deletes everything past the first 4095 bytes.

Root cause

After the size check against MAX_FILE_SIZE, file_read set to_read to max_len - 1 and returned 0.

Fix

If the file plus a trailing NUL does not fit in max_len, return -1 and a JSON error that includes the byte size. A file that fits exactly still returns the full contents.

Validation

make test_file failed on the new regression (oversize read fails) before the fix and passed afterward (83 tests run, 0 failed).

Open in Web聽View Automation聽

file_read returned success after clipping to the caller buffer. The agent
passes a 4096-byte slot, so a later write_file could replace the file with
that prefix and delete the rest.

Co-authored-by: esadrianno <esadrianno@gmail.com>
@adriannoes

Copy link
Copy Markdown
Collaborator

Superseded by #120: consolidated into the operator-authored branch fix/file-read-bounds (same fix, re-validated with CI=true make test and make static). Closing in favor of the consolidation.

@adriannoes adriannoes closed this Oct 16, 2026
@adriannoes
adriannoes deleted the cursor/high-severity-issues-ed43 branch October 16, 2026 02:59
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.

2 participants