diff --git a/rai/core_test/wallet.cpp b/rai/core_test/wallet.cpp index 89e464ba..701e2016 100644 --- a/rai/core_test/wallet.cpp +++ b/rai/core_test/wallet.cpp @@ -588,6 +588,15 @@ TEST (wallet_store, fail_import_bad_password) ASSERT_TRUE (error); } +TEST (wallet_store, fail_import_corrupt) +{ + rai::system system (24000, 2); + auto wallet1 (system.wallet (1)); + std::string json; + auto error (wallet1->import (json, "1")); + ASSERT_TRUE (error); +} + // Test arbitrary work can be generated TEST (wallet, empty_work) { diff --git a/rai/node/wallet.cpp b/rai/node/wallet.cpp index 208d69a2..6e5846d6 100644 --- a/rai/node/wallet.cpp +++ b/rai/node/wallet.cpp @@ -405,7 +405,14 @@ environment (transaction_a.environment) assert (mdb_get (transaction_a, handle, version_special.val (), &junk) == MDB_NOTFOUND); boost::property_tree::ptree wallet_l; std::stringstream istream (json_a); - boost::property_tree::read_json (istream, wallet_l); + try + { + boost::property_tree::read_json (istream, wallet_l); + } + catch (...) + { + init_a = true; + } for (auto i (wallet_l.begin ()), n (wallet_l.end ()); i != n; ++i) { rai::uint256_union key;