Avoid big strings on the stack

Previous code resulted in RangeErrors by potentially creating big
strings.

Fixes issue #1065
This commit is contained in:
Samuel Mannehed 2018-06-14 16:52:36 +02:00
parent 362bd5e3a2
commit db9daa98a5
1 changed files with 7 additions and 1 deletions

View File

@ -101,7 +101,13 @@ Websock.prototype = {
rQshiftStr: function (len) { rQshiftStr: function (len) {
if (typeof(len) === 'undefined') { len = this.rQlen(); } if (typeof(len) === 'undefined') { len = this.rQlen(); }
const arr = this.rQshiftBytes(len); 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) { rQshiftBytes: function (len) {