From 73deb5430e7d2af046754e4518c44d449d20e7d8 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Mon, 25 Jul 2016 21:44:34 -0700 Subject: [PATCH] bip151: max message size. --- lib/bcoin/bip151.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/bcoin/bip151.js b/lib/bcoin/bip151.js index 5a71ed2a..c2d29e1f 100644 --- a/lib/bcoin/bip151.js +++ b/lib/bcoin/bip151.js @@ -79,7 +79,6 @@ BIP151Stream.prototype.init = function init(publicKey) { }; BIP151Stream.prototype.maybeRekey = function maybeRekey(data) { - var self = this; this.processed += data.length; if (this.processed >= this.highWaterMark) { this.processed -= this.highWaterMark; @@ -171,7 +170,11 @@ BIP151Stream.prototype.feed = function feed(data) { this.waiting = this.decryptSize(chunk) + 16; - if (this.waiting - 32 > constants.MAX_MESSAGE) { + // Allow 3 batched packets of max message size. + // Not technically standard, but this protects us + // from buffering tons of data due to either an + // potential dos'er or a cipher state mismatch. + if (this.waiting - 32 > constants.MAX_MESSAGE * 3) { this.waiting = 0; this.emit('error', new Error('Packet too large.')); continue;