fix(process): refuse malformed timeouts for stoppable commands
Since a stoppable command keeps its own deadline, execFile no longer validated its timeout. A negative, NaN, fractional or infinite value then started the command with no deadline (or one setTimeout coerced) instead of failing with ERR_OUT_OF_RANGE as execFile does. Apply execFile's unsigned-integer contract before spawning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c89b3a00dc
commit
59c91c88fe
@@ -53,6 +53,19 @@ const timeoutError = (
|
||||
return error;
|
||||
};
|
||||
|
||||
/**
|
||||
* Node's execFile contract for `timeout`. A stoppable command keeps its own
|
||||
* deadline, so it must refuse the values execFile would refuse.
|
||||
*/
|
||||
const invalidTimeout = (timeout: number): RangeError | undefined => {
|
||||
if (Number.isSafeInteger(timeout) && timeout >= 0) return undefined;
|
||||
const error = new RangeError(
|
||||
`The value of "timeout" is out of range. It must be an unsigned integer. Received ${String(timeout)}`,
|
||||
);
|
||||
Reflect.set(error, "code", "ERR_OUT_OF_RANGE");
|
||||
return error;
|
||||
};
|
||||
|
||||
/** Captured subprocess output read from an execFileOutput rejection. */
|
||||
export interface ExecFileOutputFailure {
|
||||
readonly stdout: string;
|
||||
@@ -93,6 +106,14 @@ export const execFileOutput = (
|
||||
): Promise<{ readonly stdout: string; readonly stderr: string }> =>
|
||||
new Promise((resolve, reject) => {
|
||||
const { stopSignal, signal, timeout, ...execOptions } = options;
|
||||
const invalid =
|
||||
stopSignal === undefined || timeout === undefined
|
||||
? undefined
|
||||
: invalidTimeout(timeout);
|
||||
if (invalid !== undefined) {
|
||||
reject(invalid);
|
||||
return;
|
||||
}
|
||||
if (stopSignal !== undefined && signal?.aborted === true) {
|
||||
reject(abortError(signal));
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user