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)
committerGavin Andresen <gavinandresen@gmail.com>
Tue, 19 Jun 2012 19:38:45 +0000 (15:38 -0400)
In LoadExternalBlockFile(), errors are already caught... silently.
Add a warning message, even though we do not abort the program due to
load error.

src/main.h

index 262e77e..96187d3 100644 (file)
@@ -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))