From: Jeff Garzik Date: Tue, 22 May 2012 19:23:17 +0000 (-0400) Subject: Prevent crashes due to missing or corrupted blk????.dat records X-Git-Tag: v0.4.0-unstable~129^2~5 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=57ca021e7ee2fb80b4c06605b2126d54135ba7ff Prevent crashes due to missing or corrupted blk????.dat records In LoadExternalBlockFile(), errors are already caught... silently. Add a warning message, even though we do not abort the program due to load error. --- diff --git a/src/main.h b/src/main.h index 262e77e..96187d3 100644 --- a/src/main.h +++ b/src/main.h @@ -594,7 +594,13 @@ public: // Read transaction if (fseek(filein, pos.nTxPos, SEEK_SET) != 0) return error("CTransaction::ReadFromDisk() : fseek failed"); - filein >> *this; + + try { + filein >> *this; + } + catch (std::exception &e) { + return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__); + } // Return file pointer if (pfileRet) @@ -976,7 +982,12 @@ public: filein.nType |= SER_BLOCKHEADERONLY; // Read block - filein >> *this; + try { + filein >> *this; + } + catch (std::exception &e) { + return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__); + } // Check the header if (!CheckProofOfWork(GetHash(), nBits))