Reject non-regular files before reading - #29428
Conversation
bb6592c to
6927379
Compare
teknium1
left a comment
There was a problem hiding this comment.
Thanks for extending the device-symlink protection to the broader non-regular-file class. The premise remains valid on current main: tools/file_operations.py:1101-1160 still runs wc, head, and sed without a regular-file preflight, and tools/file_operations.py:1239-1259 similarly reaches cat through read_file_raw.
Problems
- The proposed tool-layer
Path.exists()/Path.is_file()check cannot be carried forward unchanged. Current main resolves container paths asPurePosixPathattools/file_tools.py:440-446, so host filesystem inspection is unavailable and would fail before the backend-side read guard runs. - The new general guard coverage is mocked only. The repository’s rubric calls for E2E coverage for file I/O and remote backends; the PR should exercise real directory/FIFO targets and the backend-aware resolution path.
Suggested changes
- Put the authoritative regular-file check in
ShellFileOperations.read_fileandread_file_rawso it executes in the selected terminal backend, while retaining the existing early known-device/symlink guard attools/file_tools.py:544-581. - Add real special-file regressions, including a container/backend-path case.
This is an automated hermes-sweeper review.
| @@ -461,6 +469,14 @@ def read_file_tool(path: str, offset: int = 1, limit: int = 500, task_id: str = | |||
| }) | |||
There was a problem hiding this comment.
Please avoid carrying this host-side Path.exists() / Path.is_file() guard forward unchanged. Current main resolves container-backend paths as PurePosixPath (tools/file_tools.py:440-446), so the regular-file inspection must run through ShellFileOperations in the selected backend rather than on the host.
|
Closing with credit: you were the FIRST to identify this bug class (May 20) — read_file hanging on non-regular files that the name-based device blocklist cannot see. The class is now fixed on main by two complementary guards: a host-side stat-type check (#82792, 0e63ed1) and a shell-layer probe covering all backends including remote (#83008, e0b5005, salvaged from #82075). We went with the #82075 mechanism for the shell layer because it folds the [ -f ] test into the existing wc -c invocation — same coverage as your preflight approach but without the extra shell round-trip per read. Your regression tests' shape (symlinked devices, command-ordering assertions) informed the final test suite. Thank you for finding this three months before anyone else! |
Summary
Validation