@@ -4370,12 +4370,14 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
43704370 nRewind++; // start one byte further next time, in case of failure
43714371 blkdat.SetLimit (); // remove former limit
43724372 unsigned int nSize = 0 ;
4373+ unsigned char rewindbyte=0 ;
43734374 try {
43744375 // locate a header
43754376 unsigned char buf[CMessageHeader::MESSAGE_START_SIZE];
43764377 blkdat.FindByte (chainparams.MessageStart ()[0 ]);
43774378 nRewind = blkdat.GetPos ()+1 ;
43784379 blkdat >> buf;
4380+ rewindbyte = buf[1 ]; // rewind should position us to this byte
43794381 if (memcmp (buf, chainparams.MessageStart (), CMessageHeader::MESSAGE_START_SIZE))
43804382 continue ;
43814383 // read size
@@ -4396,6 +4398,16 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFi
43964398 std::shared_ptr<CBlock> pblock = std::make_shared<CBlock>();
43974399 CBlock& block = *pblock;
43984400 blkdat >> block;
4401+ {
4402+ // verify that we can rewind to where we *may* need to
4403+ uint64_t savepos = blkdat.GetPos ();
4404+ LogPrint (BCLog::REINDEX, " rewinding from %lu to %lu\n " , savepos, nRewind);
4405+ assert (blkdat.SetPos (nRewind));
4406+ unsigned char testbyte;
4407+ blkdat >> testbyte;
4408+ assert (testbyte == rewindbyte);
4409+ assert (blkdat.SetPos (savepos));
4410+ }
43994411 nRewind = blkdat.GetPos ();
44004412
44014413 uint256 hash = block.GetHash ();
0 commit comments