Skip to content
Permalink
Browse files Browse the repository at this point in the history
Ignore exceptions when deserializing note plaintexts
  • Loading branch information
str4d committed Sep 19, 2019
1 parent 87c45fc commit c1fbf8a
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions src/zcash/Note.cpp
Expand Up @@ -173,15 +173,21 @@ boost::optional<SaplingOutgoingPlaintext> SaplingOutgoingPlaintext::decrypt(
}

// Deserialize from the plaintext
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << pt.get();
try {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << pt.get();

SaplingOutgoingPlaintext ret;
ss >> ret;
SaplingOutgoingPlaintext ret;
ss >> ret;

assert(ss.size() == 0);
assert(ss.size() == 0);

return ret;
return ret;
} catch (const boost::thread_interrupted&) {
throw;
} catch (...) {
return boost::none;
}
}

boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::decrypt(
Expand All @@ -197,13 +203,17 @@ boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::decrypt(
}

// Deserialize from the plaintext
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << pt.get();

SaplingNotePlaintext ret;
ss >> ret;

assert(ss.size() == 0);
try {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << pt.get();
ss >> ret;
assert(ss.size() == 0);
} catch (const boost::thread_interrupted&) {
throw;
} catch (...) {
return boost::none;
}

uint256 pk_d;
if (!librustzcash_ivk_to_pkd(ivk.begin(), ret.d.data(), pk_d.begin())) {
Expand Down Expand Up @@ -243,11 +253,17 @@ boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::decrypt(
}

// Deserialize from the plaintext
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << pt.get();

SaplingNotePlaintext ret;
ss >> ret;
try {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << pt.get();
ss >> ret;
assert(ss.size() == 0);
} catch (const boost::thread_interrupted&) {
throw;
} catch (...) {
return boost::none;
}

uint256 cmu_expected;
if (!librustzcash_sapling_compute_cm(
Expand All @@ -265,8 +281,6 @@ boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::decrypt(
return boost::none;
}

assert(ss.size() == 0);

return ret;
}

Expand Down

0 comments on commit c1fbf8a

Please sign in to comment.