From 8276e70de15c5c3a7525471ad619edd1237b424a Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Thu, 6 Apr 2017 20:28:19 -0500 Subject: Adding assert to avoid a memory access violation inside of PartialMerkleTree::CalcHash() Adding comment to assert in PartialMerkleTree::CalcHash() Adding comment on CMerkleBlock indicating it calls something that contains an assert Removing EOL whitespace --- src/merkleblock.cpp | 3 +++ src/merkleblock.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp index 78d7cd6001..55f899b649 100644 --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -59,6 +59,9 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, const std::set& txids) } uint256 CPartialMerkleTree::CalcHash(int height, unsigned int pos, const std::vector &vTxid) { + //we can never have zero txs in a merkle block, we always need the coinbase tx + //if we do not have this assert, we can hit a memory access violation when indexing into vTxid + assert(vTxid.size() != 0); if (height == 0) { // hash at height 0 is the txids themself return vTxid[pos]; diff --git a/src/merkleblock.h b/src/merkleblock.h index de4c5c8d29..f590c487de 100644 --- a/src/merkleblock.h +++ b/src/merkleblock.h @@ -121,6 +121,8 @@ public: /** * Used to relay blocks as header + vector * to filtered nodes. + * + * NOTE: The class assumes that the given CBlock has *at least* 1 transaction. If the CBlock has 0 txs, it will hit an assertion. */ class CMerkleBlock { -- cgit v1.2.3