Avoid shell execution in ReadFileTool ranged reads#5268
Open
petrmarinec wants to merge 2 commits intogoogle:mainfrom
Open
Avoid shell execution in ReadFileTool ranged reads#5268petrmarinec wants to merge 2 commits intogoogle:mainfrom
petrmarinec wants to merge 2 commits intogoogle:mainfrom
Conversation
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
ReadFileToolhandles ranged reads by buildingcat -n '{path}' | sed -n ...from the caller-suppliedpath, while full reads useenvironment.read_file(path)and Python slicing. Shell metacharacters inpathare therefore interpreted by the shell in the ranged-read branch instead of being treated as a literal file path.Solution:
Remove the shell-based ranged-read branch and reuse the existing Python file-read logic for all reads. This keeps ranged output behavior while eliminating the shell dependency from
ReadFileTool.Testing Plan
Unit Tests:
Passed locally in Linux Docker (
python:3.11-bookworm):pytest tests/unittests/tools/test_environment_tools.py tests/unittests/tools/environment_simulationpytest tests/unittests/tools1519 passedManual End-to-End (E2E) Tests:
origin/main, a rangedReadFileToolcall with a crafted path wrote a proof file in the working directory.File not found: ...and no proof file is written.Checklist
Additional context
This is a small fix that removes the shell-based ranged-read implementation and makes
ReadFileTooluse the same direct file-read path for both full reads and ranged reads.