From 231f56b10de806a315b56585af6eb3bba86d6ce8 Mon Sep 17 00:00:00 2001 From: theanarkh Date: Fri, 22 Jul 2022 01:28:19 +0800 Subject: [PATCH] child_process: do not need to count length when maxBuffer is Infinity PR-URL: https://github.com/nodejs/node/pull/43822 Reviewed-By: Antoine du Hamel Reviewed-By: Chengzhong Wu --- lib/child_process.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/child_process.js b/lib/child_process.js index 12c2d7e572c8d5..388cbc68dbd0b0 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -448,6 +448,11 @@ function execFile(file, args = [], options, callback) { child.stdout.setEncoding(encoding); child.stdout.on('data', function onChildStdout(chunk) { + // Do not need to count the length + if (options.maxBuffer === Infinity) { + ArrayPrototypePush(_stdout, chunk); + return; + } const encoding = child.stdout.readableEncoding; const length = encoding ? Buffer.byteLength(chunk, encoding) : @@ -473,6 +478,11 @@ function execFile(file, args = [], options, callback) { child.stderr.setEncoding(encoding); child.stderr.on('data', function onChildStderr(chunk) { + // Do not need to count the length + if (options.maxBuffer === Infinity) { + ArrayPrototypePush(_stderr, chunk); + return; + } const encoding = child.stderr.readableEncoding; const length = encoding ? Buffer.byteLength(chunk, encoding) : @@ -487,7 +497,7 @@ function execFile(file, args = [], options, callback) { ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr'); kill(); } else { - _stderr.push(chunk); + ArrayPrototypePush(_stderr, chunk); } }); }