]> git.proxmox.com Git - mirror_novnc.git/blobdiff - core/inflator.js
Handle errors from zlib/pako
[mirror_novnc.git] / core / inflator.js
index 0eab8fe48c2ced5a00c07c098f22681d95dd8093..39db447a10250c9e8d3edbd9a20279a0e1f77bda 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * noVNC: HTML5 VNC client
+ * Copyright (C) 2020 The noVNC Authors
+ * Licensed under MPL 2.0 (see LICENSE.txt)
+ *
+ * See README.md for usage and integration instructions.
+ */
+
 import { inflateInit, inflate, inflateReset } from "../vendor/pako/lib/zlib/inflate.js";
 import ZStream from "../vendor/pako/lib/zlib/zstream.js";
 
@@ -11,7 +19,7 @@ export default class Inflate {
         inflateInit(this.strm, this.windowBits);
     }
 
-    inflate(data, flush, expected) {
+    inflate(data, expected) {
         this.strm.input = data;
         this.strm.avail_in = this.strm.input.length;
         this.strm.next_in = 0;
@@ -27,7 +35,14 @@ export default class Inflate {
 
         this.strm.avail_out = this.chunkSize;
 
-        inflate(this.strm, flush);
+        let ret = inflate(this.strm, 0); // Flush argument not used.
+        if (ret < 0) {
+            throw new Error("zlib inflate failed");
+        }
+
+        if (this.strm.next_out != expected) {
+            throw new Error("Incomplete zlib block");
+        }
 
         return new Uint8Array(this.strm.output.buffer, 0, this.strm.next_out);
     }