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();