From e9022983f15382bac8cec08756408d514b4f7a7e Mon Sep 17 00:00:00 2001 From: Maja Frydrychowicz Date: Fri, 7 Aug 2020 09:08:01 +0000 Subject: [PATCH] Bug 1632722 - IO.read hits 'too many arguments' r=remote-protocol-reviewers,jgraham Differential Revision: https://phabricator.services.mozilla.com/D86262 --- remote/domains/parent/IO.jsm | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/remote/domains/parent/IO.jsm b/remote/domains/parent/IO.jsm index 4346f88d41b4..c6213cf862fb 100644 --- a/remote/domains/parent/IO.jsm +++ b/remote/domains/parent/IO.jsm @@ -101,8 +101,17 @@ class IO extends Domain { const bytes = await stream.read(chunkSize); // Each UCS2 character has an upper byte of 0 and a lower byte matching - // the binary data - const data = btoa(String.fromCharCode.apply(null, bytes)); + // the binary data. Using a loop here prevents us from hitting the browser's + // internal `arguments.length` limit. + const ARGS_MAX = 262144; + const stringData = []; + for (let i = 0; i < bytes.length; i += ARGS_MAX) { + let argsChunk = Math.min(bytes.length, i + ARGS_MAX); + stringData.push( + String.fromCharCode.apply(null, bytes.slice(i, argsChunk)) + ); + } + const data = btoa(stringData.join("")); return { data,