file_read tool crashes with a raw ValueError instead of a descriptive ExecutionError when the path contains an embedded NUL byte #180
Labels
No labels
auto/blocked-by-deps
auto/ci-timeout
auto/claimed-implementer
auto/claimed-merge
auto/claimed-reviewer
auto/driver-down
auto/invariant-violation
auto/last-attempt-tier-0
auto/last-attempt-tier-1
auto/last-attempt-tier-2
auto/last-attempt-tier-min
Automation Tracking
auto/needs-conflict-resolution
auto/needs-implementer
auto/postmortem
auto/ready-to-merge
auto/restart-throttled
auto/revert
auto/sentinel
auto/stale-inactivity
auto/unstable
Blocked
Bounty
$100
Bounty
$1000
Bounty
$10000
Bounty
$20
Bounty
$2000
Bounty
$250
Bounty
$50
Bounty
$500
Bounty
$5000
Bounty
$750
MoSCoW
Could have
MoSCoW
Must have
MoSCoW
Should have
Needs Feedback
Points
1
Points
13
Points
2
Points
21
Points
3
Points
34
Points
5
Points
55
Points
8
Points
88
Priority
Backlog
Priority
CI Blocker
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Signed-off: Owner
Signed-off: Scrum Master
Signed-off: Tech Lead
Spike
State
Completed
State
Duplicate
State
In Progress
State
In Review
State
Paused
State
Unverified
State
Verified
State
Wont Do
Type
Automation
Type
Bug
Type
Discussion
Type
Documentation
Type
Epic
Type
Feature
Type
Legendary
Type
Refactor
Type
Support
Type
Task
Type
Testing
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Depends on
Reference
cleveragents/cleveractors-core#180
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Metadata
Commit Message:
fix(agents): reject file_read path arguments containing an embedded NUL byte before touching the filesystemBranch: bugfix/m1-file-read-nul-byte-path
Background and context
ToolAgent._file_read_tool(src/cleveractors/agents/tool.py) validates thefileargument for emptiness, for shell-command-like syntax (pipe/redirect/semicolon characters and known shell command names), and — only whensafe_modeis enabled — for..traversal, a leading/, and (viaSandboxRootPolicy) a symlink-escape check that callsos.path.realpath(filepath)directly (notry/exceptaround it, at the line implementing the ADR-2035 D-4 symlink-escape closure). None of these checks reject afilestring containing an embedded NUL byte (\x00) before it reaches thatos.path.realpath()call. CPython'sosmodule raises a rawValueError("embedded null character"/"embedded null byte" in path) for any path argument containing a NUL byte, and this happens below the tool's own validation layer and before_file_read_tool's owntry/exceptblock (which only wraps the lateros.path.isdir/file-read logic and only catchesFileNotFoundError,OSError, andUnicodeDecodeError) is even entered.This is the same defect class reported in #175 for
file_write(a corrupted/malformedfileargument sails through path validation and only fails deep inside a filesystem call) — discovered while auditingfile_read,shell, andpython_execfor the same class of defect, at the maintainer's request, following up on #175/#176/PR #178.Current behavior
Confirmed directly against this branch by invoking the tool programmatically:
raises:
This propagates uncaught out of
_file_read_tooland_execute_tool. When the tool agent is driven throughToolAgent.invoke()— the graph-node dispatch entry point documented in its own docstring as "Path B" — there is no surrounding catch-all at all, so the rawValueErrorreaches the caller directly instead of the agent'sExecutionErrorcontract. When driven instead throughprocess_message(), the outer genericexcept Exception as ethere does catch it and re-wraps it asExecutionError(f"Tool execution failed: {str(e)}")— but the resulting message is still just Python's raw, low-level text ("Tool execution failed: lstat: embedded null character in path"), with no indication of which character was invalid or that this was a validation failure rather than a filesystem failure.Expected behavior
_file_read_toolrejects afileargument containing a NUL byte (or other ASCII control character illegal in a filename) with a descriptiveExecutionError, raised before any call that touches the filesystem (os.path.realpath,os.path.isdir, the shared file-read core). The behavior must be identical regardless of which public entry point (invoke()orprocess_message()) dispatches the call — a rawValueErrormust never reach either caller.Acceptance criteria
file_readcall whosefileargument contains an embedded NUL byte (\x00) or another ASCII control character (\x01-\x1F) is rejected with anExecutionErrorbeforeos.path.realpath,os.path.isdir, or any other OS call is reached.file_readis dispatched viaToolAgent.invoke()orToolAgent.process_message()— no rawValueErrorreaches either caller.ExecutionErrormessage names the specific problem found (e.g. an embedded NUL byte or control character), not a propagated low-levelValueError/OSErrorstring._file_read_toolcontinue to pass unchanged.Supporting information
ToolAgent._file_read_toolinsrc/cleveractors/agents/tool.py. Crash site: the unguardedos.path.realpath(filepath)call reached by thesafe_modesymlink-escape branch, which executes before_file_read_tool's owntryblock begins.file_write's_validate_file_path_safety, which only checks for traversal/absolute-path/home-directory escapes, not well-formedness)._validate_file_path_safetyhas an equally unguardedos.path.realpath()call at its own symlink-escape check and is equally susceptible to the embedded-NUL-byte crash described here; since #175's own subtasks already call for extending its path-validation fix to "file_write, and any sibling tools such as file_read", whichever of these two issues lands second should factor the character/well-formedness check into one shared helper so the two call sites cannot drift apart.open/ TOCTOU hardening) — those address a different, already-solved concern (race-safe resolution), not malformed-input rejection.Subtasks
_file_read_tool(or a helper shared with_validate_file_path_safety) that rejects an embedded NUL byte and other filename-illegal control characters, raising a descriptiveExecutionError, before any filesystem call._file_read_toolthat can reachos.path.realpath/os.path.isdir, including both thesafe_modesymlink-escape branch and the main directory-listing/file-read path.features/covering afile_readpath with an embedded NUL byte and a path with another illegal control character, confirming the failure is anExecutionError(not a rawValueError) from both theinvoke()andprocess_message()entry points, and confirming valid paths remain unaffected.nox -s coverage_report.nox(all default sessions), fix any errors.Definition of Done
This issue is complete when:
Type/TestingTDD issue exists, the TDD scenario (tagged@tdd_expected_fail) is merged first, and this issue's Forgejo dependency correctly shows it depends on that TDD issue.Note for triage
This fits Epic #77 ("LLM Agent Runtime Stabilization") as a tool-dispatch input-validation hardening item, directly alongside its sibling #175 (same defect class,
file_write) — recommend linking it there, but leaving the final call, milestone assignment, and MoSCoW to maintainer/project-owner triage.CoreRasurae referenced this issue2026-11-30 12:18:16 +00:00
CoreRasurae referenced this issue2026-11-30 12:18:16 +00:00
The problem described in this issue has already been addressed when handling issue #175