From a2de1ea2d5776289c247bbc18c1ed13e16a4169f Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Tue, 22 May 2012 15:23:17 -0400 Subject: [PATCH] Prevent crashes due to missing or corrupted blk????.dat records --- src/main.h | 15 +++++++++++++-- 1 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.h b/src/main.h index b1c7885..44624f5 100644 --- a/src/main.h +++ b/src/main.h @@ -601,7 +601,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) @@ -993,7 +999,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)) -- 1.7.1