From: Samuel Mannehed Date: Thu, 14 Jun 2018 14:52:36 +0000 (+0200) Subject: Avoid big strings on the stack X-Git-Tag: v1.1.0~70 X-Git-Url: https://git.proxmox.com/?p=mirror_novnc.git;a=commitdiff_plain;h=db9daa98a5dedc3ebefea3fe7c09a3fb505fa366 Avoid big strings on the stack Previous code resulted in RangeErrors by potentially creating big strings. Fixes issue #1065 --- diff --git a/core/websock.js b/core/websock.js index 9291d4e..6b03361 100644 --- a/core/websock.js +++ b/core/websock.js @@ -101,7 +101,13 @@ Websock.prototype = { rQshiftStr: function (len) { if (typeof(len) === 'undefined') { len = this.rQlen(); } const arr = this.rQshiftBytes(len); - return String.fromCharCode.apply(null, arr); + let str = ""; + // Handle large arrays in steps to avoid long strings on the stack + for (let i = 0; i < len; i += 4096) { + let part = arr.slice(i, i + Math.min(4096, len)); + str = str.concat(String.fromCharCode.apply(null, part)); + } + return str; }, rQshiftBytes: function (len) {