From 04840223eed99cd66213a5c870e9eb0e9482ca4b 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 59259ff96a9225..e80e4003dc46e6 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -458,6 +458,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) : @@ -483,6 +488,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) : @@ -497,7 +507,7 @@ function execFile(file, args, options, callback) { ex = new ERR_CHILD_PROCESS_STDIO_MAXBUFFER('stderr'); kill(); } else { - _stderr.push(chunk); + ArrayPrototypePush(_stderr, chunk); } }); }