fix(file): do not collapse missing path components onto ancestor files - #67
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(file): do not collapse missing path components onto ancestor files#67cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
write_file treated an existing ancestor as the fopen target when the requested nested path did not exist, truncating a file used as a directory or overwriting a same-named file in a parent directory. Co-authored-by: esadrianno <[email protected]>
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.
Bug and impact
With sandbox
workspace_onlyenabled (the documented default),write_fileon a nested path that does not exist yet could silently destroy an existing workspace file:The same ancestor collapse made
read_fileonsecret.env/xreturn the contents ofsecret.env.Agent-generated nested paths (or a typo that treats a file as a directory) are a realistic trigger. The tool returned
{"status":"ok"}while clobbering the wrong file.Root cause
path_within_workspacewalksdirnameuntil an existing ancestorrealpaths, which is correct as a membership check.file_writethen used that ancestor as thefopentarget: if it was a regular file, it opened it with"w"; otherwise it appended only the original basename. Missing intermediate directories therefore collapsed onto a parent file with the same name.Fix
Resolve the intended write path separately:
parent/basenameread_file/list_dirnowrealpaththe requested path itself instead of opening the ancestor.Validation
make CI=true test_file && ./build/test_file— 34 tests, 0 failedimportant.md; write tomissing_dir/notes.mdmust fail and preserve workspacenotes.md