Prevent crashes due to missing or corrupted blk????.dat records
authorJeff Garzik <jgarzik@exmulti.com>
Tue, 22 May 2012 19:23:17 +0000 (15:23 -0400)
committerLuke Dashjr <luke-jr+git@utopios.org>
Tue, 22 May 2012 22:50:02 +0000 (22:50 +0000)
src/main.h

index b1c7885..44624f5 100644 (file)
@@ -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))