Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion tools/terminal_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2544,6 +2544,12 @@ def _read_script_in_env(script_path: str) -> Optional[str]:
metadata = local_path.stat()
if stat.S_ISREG(metadata.st_mode) and metadata.st_size <= 1024 * 1024:
data = local_path.read_bytes()
# Binary (ELF/Mach-O/PE/etc.) is not a shell script;
# scanning its decoded bytes would tokenize machine
# code and feed NUL-containing junk paths into the
# recursion (#76762). Mirror _read_referenced_script.
if b"\x00" in data:
return None
if len(data) <= 1024 * 1024:
return data.decode("utf-8", errors="replace")
except Exception:
Expand All @@ -2552,7 +2558,14 @@ def _read_script_in_env(script_path: str) -> Optional[str]:
try:
result = env.execute(f"cat {shlex.quote(script_path)}")
if result.get("returncode", -1) == 0:
return result.get("output", "")
output = result.get("output", "")
# Binary content (ELF/Mach-O/PE) read through `cat`
# carries NUL bytes; scanning it would tokenize machine
# code into junk paths and crash the recursion with
# "embedded null byte" (#76762). Mirror the local path.
if "\x00" in output:
return None
return output
except Exception:
pass
return None
Expand Down