From b91b1e8edccc978dbc94d1a22651d298d6cdb37a Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 7 Sep 2020 12:58:52 +0200 Subject: [PATCH] Handle empty rects in RAW decoder as well It was overlooked in the previous commit because we couldn't feed empty data messages through the test framework. --- core/decoders/raw.js | 4 ++++ tests/test.copyrect.js | 8 +++++++- tests/test.hextile.js | 8 +++++++- tests/test.raw.js | 8 +++++++- tests/test.rre.js | 8 +++++++- tests/test.tight.js | 8 +++++++- tests/test.tightpng.js | 8 +++++++- 7 files changed, 46 insertions(+), 6 deletions(-) diff --git a/core/decoders/raw.js b/core/decoders/raw.js index d7a77ec9..e8ea178e 100644 --- a/core/decoders/raw.js +++ b/core/decoders/raw.js @@ -13,6 +13,10 @@ export default class RawDecoder { } decodeRect(x, y, width, height, sock, display, depth) { + if ((width === 0) || (height === 0)) { + return true; + } + if (this._lines === 0) { this._lines = height; } diff --git a/tests/test.copyrect.js b/tests/test.copyrect.js index c67caeb5..90ba0c68 100644 --- a/tests/test.copyrect.js +++ b/tests/test.copyrect.js @@ -17,7 +17,13 @@ function testDecodeRect(decoder, x, y, width, height, data, display, depth) { decoder.decodeRect(x, y, width, height, sock, display, depth); }); - sock._websocket._receiveData(new Uint8Array(data)); + // Empty messages are filtered at multiple layers, so we need to + // do a direct call + if (data.length === 0) { + decoder.decodeRect(x, y, width, height, sock, display, depth); + } else { + sock._websocket._receiveData(new Uint8Array(data)); + } display.flip(); } diff --git a/tests/test.hextile.js b/tests/test.hextile.js index a703100f..a7034f05 100644 --- a/tests/test.hextile.js +++ b/tests/test.hextile.js @@ -17,7 +17,13 @@ function testDecodeRect(decoder, x, y, width, height, data, display, depth) { decoder.decodeRect(x, y, width, height, sock, display, depth); }); - sock._websocket._receiveData(new Uint8Array(data)); + // Empty messages are filtered at multiple layers, so we need to + // do a direct call + if (data.length === 0) { + decoder.decodeRect(x, y, width, height, sock, display, depth); + } else { + sock._websocket._receiveData(new Uint8Array(data)); + } display.flip(); } diff --git a/tests/test.raw.js b/tests/test.raw.js index 13b3502c..bc7adc78 100644 --- a/tests/test.raw.js +++ b/tests/test.raw.js @@ -17,7 +17,13 @@ function testDecodeRect(decoder, x, y, width, height, data, display, depth) { decoder.decodeRect(x, y, width, height, sock, display, depth); }); - sock._websocket._receiveData(new Uint8Array(data)); + // Empty messages are filtered at multiple layers, so we need to + // do a direct call + if (data.length === 0) { + decoder.decodeRect(x, y, width, height, sock, display, depth); + } else { + sock._websocket._receiveData(new Uint8Array(data)); + } display.flip(); } diff --git a/tests/test.rre.js b/tests/test.rre.js index 15760520..8e006f87 100644 --- a/tests/test.rre.js +++ b/tests/test.rre.js @@ -17,7 +17,13 @@ function testDecodeRect(decoder, x, y, width, height, data, display, depth) { decoder.decodeRect(x, y, width, height, sock, display, depth); }); - sock._websocket._receiveData(new Uint8Array(data)); + // Empty messages are filtered at multiple layers, so we need to + // do a direct call + if (data.length === 0) { + decoder.decodeRect(x, y, width, height, sock, display, depth); + } else { + sock._websocket._receiveData(new Uint8Array(data)); + } display.flip(); } diff --git a/tests/test.tight.js b/tests/test.tight.js index 4aa47d70..cc5db36b 100644 --- a/tests/test.tight.js +++ b/tests/test.tight.js @@ -17,7 +17,13 @@ function testDecodeRect(decoder, x, y, width, height, data, display, depth) { decoder.decodeRect(x, y, width, height, sock, display, depth); }); - sock._websocket._receiveData(new Uint8Array(data)); + // Empty messages are filtered at multiple layers, so we need to + // do a direct call + if (data.length === 0) { + decoder.decodeRect(x, y, width, height, sock, display, depth); + } else { + sock._websocket._receiveData(new Uint8Array(data)); + } display.flip(); } diff --git a/tests/test.tightpng.js b/tests/test.tightpng.js index 857cd84c..cb36e99c 100644 --- a/tests/test.tightpng.js +++ b/tests/test.tightpng.js @@ -17,7 +17,13 @@ function testDecodeRect(decoder, x, y, width, height, data, display, depth) { decoder.decodeRect(x, y, width, height, sock, display, depth); }); - sock._websocket._receiveData(new Uint8Array(data)); + // Empty messages are filtered at multiple layers, so we need to + // do a direct call + if (data.length === 0) { + decoder.decodeRect(x, y, width, height, sock, display, depth); + } else { + sock._websocket._receiveData(new Uint8Array(data)); + } display.flip(); }