]> git.proxmox.com Git - mirror_novnc.git/commitdiff
Avoid big strings on the stack
authorSamuel Mannehed <samuel@cendio.se>
Thu, 14 Jun 2018 14:52:36 +0000 (16:52 +0200)
committerSamuel Mannehed <samuel@cendio.se>
Thu, 14 Jun 2018 14:59:52 +0000 (16:59 +0200)
Previous code resulted in RangeErrors by potentially creating big
strings.

Fixes issue #1065

core/websock.js

index 9291d4ed7d0afafa2a6ccab10f1e8c9e4b1b3879..6b0336157bb17ca7f806dbf999abd440bb654e9f 100644 (file)
@@ -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) {