From 2dc09f656b898021b371d8c11c3883f562e09e30 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Wed, 2 Aug 2017 15:05:52 +0200 Subject: [PATCH] test: read proper inspector message size Fix a bug when messages bigger than 64kb where incorrectly parsed by the inspector-helper. PR-URL: https://github.com/nodejs/node/pull/14596 Fixes: https://github.com/nodejs/node/issues/14507 Reviewed-By: Luigi Pinca Reviewed-By: Eugene Ostroukhov Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: James M Snell --- test/inspector/inspector-helper.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/inspector/inspector-helper.js b/test/inspector/inspector-helper.js index 35f23dfeb5cba6..2f45e21c5b0665 100644 --- a/test/inspector/inspector-helper.js +++ b/test/inspector/inspector-helper.js @@ -53,6 +53,7 @@ function sendEnd(socket) { } function parseWSFrame(buffer, handler) { + // Protocol described in https://tools.ietf.org/html/rfc6455#section-5 if (buffer.length < 2) return 0; if (buffer[0] === 0x88 && buffer[1] === 0x00) { @@ -68,7 +69,8 @@ function parseWSFrame(buffer, handler) { dataLen = buffer.readUInt16BE(2); bodyOffset = 4; } else if (dataLen === 127) { - dataLen = buffer.readUInt32BE(2); + assert(buffer[2] === 0 && buffer[3] === 0, 'Inspector message too big'); + dataLen = buffer.readUIntBE(4, 6); bodyOffset = 10; } if (buffer.length < bodyOffset + dataLen)