From b0896c8859742da7e5fb40cc4a0737c3384413c7 Mon Sep 17 00:00:00 2001 From: Jesper Alf Dam Date: Wed, 7 Aug 2019 11:12:35 +0200 Subject: [PATCH] When compacting the receive buffer don't copy unused buffer space When compacting the receive buffer, we should only copy the bytes between _rQi and _rQlen (the index of the first unread byte, and the next write position). Previously, we copied everything for _rQi up untill the end of the buffer. --- kasmweb/core/websock.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kasmweb/core/websock.js b/kasmweb/core/websock.js index 252f352..c8d90ac 100644 --- a/kasmweb/core/websock.js +++ b/kasmweb/core/websock.js @@ -247,12 +247,12 @@ export default class Websock { if (resizeNeeded) { const old_rQbuffer = this._rQ.buffer; this._rQ = new Uint8Array(this._rQbufferSize); - this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi)); + this._rQ.set(new Uint8Array(old_rQbuffer, this._rQi, this._rQlen - this._rQi)); } else { if (ENABLE_COPYWITHIN) { - this._rQ.copyWithin(0, this._rQi); + this._rQ.copyWithin(0, this._rQi, this._rQlen); } else { - this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi)); + this._rQ.set(new Uint8Array(this._rQ.buffer, this._rQi, this._rQlen - this._rQi)); } }