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;