Skip to content

Commit 8f3f62b

Browse files
UdjinM6claude
andcommitted
fix: add vtxundo size validation in SpentIndex::WriteBlock
Match the same defensive check that AddressIndex::WriteBlock performs, preventing potential out-of-bounds access on block.vtx if undo data is inconsistent. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 97dcc6d commit 8f3f62b

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/index/spentindex.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ bool SpentIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
7878

7979
// Process each non-coinbase transaction
8080
// blockundo.vtxundo[i] corresponds to block.vtx[i+1] (coinbase is skipped in undo data)
81+
if (blockundo.vtxundo.size() != block.vtx.size() - 1) {
82+
return error("%s: Undo data size mismatch for block %s (expected %zu, got %zu)", __func__,
83+
pindex->GetBlockHash().ToString(), block.vtx.size() - 1, blockundo.vtxundo.size());
84+
}
85+
8186
for (size_t i = 0; i < blockundo.vtxundo.size(); i++) {
8287
const CTransactionRef& tx = block.vtx[i + 1]; // +1 to skip coinbase
8388
const CTxUndo& txundo = blockundo.vtxundo[i];

0 commit comments

Comments
 (0)