Skip to content

Commit be0fb2c

Browse files
Crypt-iQinstagibbs
andcommitted
net: check for empty header before calling FillBlock
Previously in debug builds, this would cause an Assume crash if FillBlock had been called previously. This could happen when multiple blocktxn messages were received. Co-Authored-By: Greg Sanders <[email protected]>
1 parent 689a321 commit be0fb2c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/net_processing.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,6 +3329,16 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl
33293329

33303330
PartiallyDownloadedBlock& partialBlock = *range_flight.first->second.second->partialBlock;
33313331

3332+
if (partialBlock.header.IsNull()) {
3333+
// It is possible for the header to be empty if a previous call to FillBlock wiped the header, but left
3334+
// the PartiallyDownloadedBlock pointer around (i.e. did not call RemoveBlockRequest). In this case, we
3335+
// should not call LookupBlockIndex below.
3336+
RemoveBlockRequest(block_transactions.blockhash, pfrom.GetId());
3337+
Misbehaving(peer, "invalid compact block/non-matching block transactions");
3338+
LogDebug(BCLog::NET, "Peer %d sent compact block transactions multiple times\n", pfrom.GetId());
3339+
return;
3340+
}
3341+
33323342
// We should not have gotten this far in compact block processing unless it's attached to a known header
33333343
const CBlockIndex* prev_block{Assume(m_chainman.m_blockman.LookupBlockIndex(partialBlock.header.hashPrevBlock))};
33343344
ReadStatus status = partialBlock.FillBlock(*pblock, block_transactions.txn,
@@ -3340,6 +3350,9 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl
33403350
} else if (status == READ_STATUS_FAILED) {
33413351
if (first_in_flight) {
33423352
// Might have collided, fall back to getdata now :(
3353+
// We keep the failed partialBlock to disallow processing another compact block announcement from the same
3354+
// peer for the same block. We let the full block download below continue under the same m_downloading_since
3355+
// timer.
33433356
std::vector<CInv> invs;
33443357
invs.emplace_back(MSG_BLOCK | GetFetchFlags(peer), block_transactions.blockhash);
33453358
MakeAndPushMessage(pfrom, NetMsgType::GETDATA, invs);

0 commit comments

Comments
 (0)