Commit 6429932
fix(agent): strip null bytes from spawn args before launching task process (#813)
## Main-trunk migration
Replaces #804 after the trunk cutover. The three isolated commits now
start from the new `main`; original authorship and the contributor’s
implementation are preserved.
## Original PR body
## Problem
A task prompt containing a null byte crashes the whole cluster.
`spawnTaskProcess` passes the built args array, including the full
prompt, straight to `child_process.spawn()`. Node's
`normalizeSpawnArguments` throws `TypeError [ERR_INVALID_ARG_VALUE]` on
any argv string with an embedded null byte, because argv strings are
null terminated at the OS level and simply cannot carry one.
```
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'args[10]' must be a string without null bytes.
at normalizeSpawnArguments (node:child_process:584:3)
at spawn (node:child_process:780:13)
at spawnTaskProcess (src/agent/agent-task-executor.js:833:18)
```
Fixes #621
## Fix
Strip null bytes from string args right before the `spawn()` call in
`spawnTaskProcess` (`src/agent/agent-task-executor.js`). This is the one
place all task-run args funnel through before reaching the OS, so it
covers the prompt and any other string arg without touching
prompt-building code upstream.
Also exported `spawnTaskProcess` so it can be unit tested directly, same
as other internals already exported from this file.
## Test plan
- Added `tests/unit/spawn-null-byte-sanitization.test.js`:
- stubs `child_process.spawn` and asserts a prompt with an embedded null
byte reaches `spawn()` with the null byte stripped
- runs the real (unstubbed) `spawn()` with a null-byte-containing arg
and asserts it does not throw `ERR_INVALID_ARG_VALUE`
- Verified the test fails with `ERR_INVALID_ARG_VALUE` when the fix is
reverted, confirming it actually catches the original bug
- Full unit suite: 1212 passing, 0 new failures
- `npm run lint` / `npm run typecheck` clean on changed files (repo
currently has pre-existing, unrelated lint debt on `dev` itself, not
introduced by this change)
---------
Co-authored-by: Atharv Singh <singhatharv1919@gmail.com>1 parent 245fd9a commit 6429932
3 files changed
Lines changed: 116 additions & 2 deletions
File tree
- src
- agent
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
875 | 875 | | |
876 | 876 | | |
877 | 877 | | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
878 | 881 | | |
879 | | - | |
| 882 | + | |
880 | 883 | | |
881 | 884 | | |
882 | 885 | | |
| |||
2366 | 2369 | | |
2367 | 2370 | | |
2368 | 2371 | | |
| 2372 | + | |
2369 | 2373 | | |
2370 | 2374 | | |
2371 | 2375 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
727 | 727 | | |
728 | 728 | | |
729 | 729 | | |
730 | | - | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
731 | 734 | | |
732 | 735 | | |
733 | 736 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
0 commit comments