Throw error in plaintext deserialization

This commit is contained in:
therealyingtong 2020-06-30 05:50:10 +08:00
parent f24e706079
commit 2f4d7e35c9
2 changed files with 42 additions and 24 deletions

View File

@ -196,15 +196,18 @@ boost::optional<SaplingOutgoingPlaintext> SaplingOutgoingPlaintext::decrypt(
} }
// Deserialize from the plaintext // Deserialize from the plaintext
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); try {
ss << pt.get(); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss << pt.get();
SaplingOutgoingPlaintext ret; SaplingOutgoingPlaintext ret;
ss >> ret; ss >> ret;
assert(ss.size() == 0);
assert(ss.size() == 0); return ret;
} catch (const boost::thread_interrupted&) {
return ret; throw;
} catch (...) {
return boost::none;
}
} }
boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::decrypt( boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::decrypt(
@ -290,13 +293,18 @@ boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::attempt_sapling_enc_
}; };
// Deserialize from the plaintext // Deserialize from the plaintext
SaplingNotePlaintext plaintext; SaplingNotePlaintext ret;
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); try {
ss << encPlaintext.get(); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss >> plaintext; ss << encPlaintext.get();
assert(ss.size() == 0); ss >> ret;
assert(ss.size() == 0);
return plaintext; return ret;
} catch (const boost::thread_interrupted&) {
throw;
} catch (...) {
return boost::none;
}
} }
boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::decrypt( boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::decrypt(
@ -384,13 +392,18 @@ boost::optional<SaplingNotePlaintext> SaplingNotePlaintext::attempt_sapling_enc_
}; };
// Deserialize from the plaintext // Deserialize from the plaintext
SaplingNotePlaintext plaintext; SaplingNotePlaintext ret;
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); try {
ss << encPlaintext.get(); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss >> plaintext; ss << encPlaintext.get();
assert(ss.size() == 0); ss >> ret;
assert(ss.size() == 0);
return plaintext; return ret;
} catch (const boost::thread_interrupted&) {
throw;
} catch (...) {
return boost::none;
}
} }
boost::optional<SaplingNotePlaintextEncryptionResult> SaplingNotePlaintext::encrypt(const uint256& pk_d) const boost::optional<SaplingNotePlaintextEncryptionResult> SaplingNotePlaintext::encrypt(const uint256& pk_d) const

View File

@ -213,7 +213,12 @@ public:
template <typename Stream, typename Operation> template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action) { inline void SerializationOp(Stream& s, Operation ser_action) {
READWRITE(leadbyte); // 1 byte READWRITE(leadbyte);
if (leadbyte != 0x01 && leadbyte != 0x02) {
throw std::ios_base::failure("lead byte of SaplingNotePlaintext is not recognized");
}
READWRITE(d); // 11 bytes READWRITE(d); // 11 bytes
READWRITE(value_); // 8 bytes READWRITE(value_); // 8 bytes
READWRITE(rseed); // 32 bytes READWRITE(rseed); // 32 bytes