From 6ae75ea0978e1bdbf1270ff590824c7ab3ddae04 Mon Sep 17 00:00:00 2001 From: Rauneet Singh Date: Tue, 28 Jul 2026 17:08:45 +0530 Subject: [PATCH] child_process: fix primordials usage in stderr truncation In `execFile()`, the stderr `data` event handler was calling `chunk.slice(0, truncatedLen)` directly on the chunk object. This was inconsistent with stdout handling, which uses a safe local `slice` helper with `StringPrototypeSlice` for strings and a function wrapper for buffers. This change updates the stderr handler to use the same `slice` helper, ensuring consistent primordials usage across both stdout and stderr stream truncation. Signed-off-by: Rauneet Singh --- lib/child_process.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/child_process.js b/lib/child_process.js index 0e3e04af0d6e32..c0ad3f5d99209e 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -503,12 +503,13 @@ function execFile(file, args, options, callback) { const length = encoding ? Buffer.byteLength(chunk, encoding) : chunk.length; + const slice = encoding ? StringPrototypeSlice : + (buf, ...args) => buf.slice(...args); stderrLen += length; if (stderrLen > options.maxBuffer) { const truncatedLen = options.maxBuffer - (stderrLen - length); - ArrayPrototypePush(_stderr, - chunk.slice(0, truncatedLen)); + ArrayPrototypePush(_stderr, slice(chunk, 0, truncatedLen)); ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr'); kill();