Repository navigation
fix: match Node's argument handling in patched child_process - #335
Merged
Merged
Conversation
The child_process patch guessed where the options object sat. With an
explicit undefined/null options argument it inserted a new {} after it,
so exec(cmd, undefined, cb) passed {} as the callback and threw
ERR_INVALID_ARG_TYPE. null options crashed on null.env, and the
caller's options, env and args array were mutated.
Normalize each call the way Node does (normalizeExecArgs,
normalizeExecFileArgs, normalizeSpawnArguments), inject PKG_EXECPATH
into a copy of the options, and pass input Node rejects through
untouched so Node throws its own error.
Closes #334
Member
Author
finalize-pr — 1 round, merge-readyDeclined
Noted, not fixed (dropped by the author)
|
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.
Closes #334
Problem
The
child_processpatch inprelude/bootstrap-shared.js(setOptsEnv) guessed where the options object sat. When that slot held an explicitundefined, it inserted a new{}after it instead of replacing it:This is not a regression. The logic dates back to vercel/pkg (2017); #229 only moved it into
bootstrap-shared.js. It surfaced now because systeminformation 5.33.23 callsexec(cmd, undefined, cb).Other differences from plain Node in the same code:
exec(cmd, null, cb),execSync(cmd, null)null.envexecFile(f, undefined, cb)spawn(f, args, null)ERR_INVALID_ARG_TYPEnull.envopts.env,envand theargsarray mutatedFix
Each family now has a normalizer that mirrors Node's own (
normalizeExecArgs,normalizeExecFileArgs,normalizeSpawnArgumentsinlib/child_process.js; these are the same in v22 and v24). Each one produces the canonical argument list, andPKG_EXECPATHis injected into a copy of the options. Some details follow Node exactly:exec/execSyncaccept any options value (Node spreads it), soexecSync(cmd, 'str')still getsPKG_EXECPATH.envis read, so an inheritedoptions.envis ignored, as in Node. Env keys are copied withfor-in, so inherited env keys are kept, as in Node.For spawn/execFile input that Node rejects, the normalizer returns
nulland the call passes through untouched, so Node throws its own error. Because the args array is always canonical now,modifyShortno longer inserts[].Standard and SEA modes share this code.
Tests
test/unit/child-process.test.ts: 36 call forms run on stock Node first, then patched, and must give the same outcome (error code and message, or stdout). This includes the reject paths and inherited env/options. Further checks:PKG_EXECPATHreaches the child for all six functions, a caller-set value is kept, and the caller's options, env and args are not mutated. 23 of the 45 tests fail onmain.test/test-50-spawn/test-exec-4.js: the reproduction from the issue. Node and the packaged binary must print the same output. Checked by hand in both standard and SEA mode.