From d9c5326f1773b63792eab410ca5119c3c4176d41 Mon Sep 17 00:00:00 2001 From: Kris Nuttycombe Date: Tue, 5 Jul 2022 17:24:39 -0600 Subject: [PATCH] Ensure that the node has position information before attempting to read block data. --- src/init.cpp | 4 ++-- src/main.cpp | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 39eb438e2..d7428ebca 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -712,8 +712,8 @@ void ThreadStartWalletNotifier() // We know we have the genesis block. assert(pindexFork != nullptr); - if (pindexLastTip->nHeight < pindexFork->nHeight || - pindexLastTip->nHeight - pindexFork->nHeight < 100) + if ((pindexLastTip->nHeight < pindexFork->nHeight || pindexLastTip->nHeight - pindexFork->nHeight < 100) && + !pindexLastTip->GetBlockPos().IsNull()) { break; } diff --git a/src/main.cpp b/src/main.cpp index 37b991bd6..167e42120 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2241,6 +2241,11 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus: bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams) { + if (pindex->GetBlockPos().IsNull()) { + return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): block index entry does not provide a valid disk position for block %s at %s", + pindex->ToString(), pindex->GetBlockPos().ToString()); + } + if (!ReadBlockFromDisk(block, pindex->GetBlockPos(), consensusParams)) return false; if (block.GetHash() != pindex->GetBlockHash())