From f20f524af010bbe3ddb458feb268a9b758beb0f6 Mon Sep 17 00:00:00 2001 From: Artem Titoulenko Date: Wed, 8 Sep 2021 12:38:42 -0400 Subject: [PATCH] asserts for FLAP, SNAC headers --- src/structures.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/structures.js b/src/structures.js index 2b135f3..db8eca0 100644 --- a/src/structures.js +++ b/src/structures.js @@ -31,6 +31,7 @@ class TLV { class SNAC { static fromBuffer(buf, payloadLength = 0) { + assert(buf.length >= 10, 'Expected 10 bytes for SNAC header'); const family = buf.slice(0,2).readInt16BE(0); const service = buf.slice(2,4).readInt16BE(0); const flags = buf.slice(4, 6); @@ -85,7 +86,8 @@ class SNAC { class FLAP { static fromBuffer(buf) { - assert.equal(buf[0], 0x2a, 'Expected 0x2a FLAP header'); + assert.equal(buf[0], 0x2a, 'Expected 0x2a at start of FLAP header'); + assert(buf.length >= 6, 'Expected at least 6 bytes for FLAP header'); const channel = buf.readInt8(1); const sequenceNumber = buf.slice(2,4).readInt16BE(0); const payloadLength = buf.slice(4, 6).readInt16BE(0);