diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index ad581d40..e4a0e3ca 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -195,7 +195,9 @@ Block.prototype._checkBlock = function checkBlock() { } // First TX must be a coinbase - if (this.txs[0].inputs.length !== 1 || +this.txs[0].inputs[0].out.hash !== 0) { + if (!this.txs.length + || this.txs[0].inputs.length !== 1 + || +this.txs[0].inputs[0].out.hash !== 0) { return false; } diff --git a/lib/bcoin/protocol/parser.js b/lib/bcoin/protocol/parser.js index f7c8dfbb..401a7967 100644 --- a/lib/bcoin/protocol/parser.js +++ b/lib/bcoin/protocol/parser.js @@ -215,7 +215,7 @@ Parser.prototype.parseMerkleBlock = function parseMerkleBlock(p) { }; Parser.prototype.parseBlock = function parseBlock(p) { - if (p.length < 84) + if (p.length < 81) return this._error('Invalid block size'); var result = readIntv(p, 80); @@ -223,10 +223,12 @@ Parser.prototype.parseBlock = function parseBlock(p) { var totalTX = result.r; var txs = []; - for (var i = 0; i < totalTX; i++) { - var tx = this.parseTX(p.slice(off)); - off += tx._off; - txs.push(tx); + if (p.length >= off + 10) { + for (var i = 0; i < totalTX; i++) { + var tx = this.parseTX(p.slice(off)); + off += tx._off; + txs.push(tx); + } } return {