mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
tests: Add deserialization fuzzing harnesses
This commit is contained in:
@@ -26,19 +26,31 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
int nVersion;
|
||||
ds >> nVersion;
|
||||
ds.SetVersion(nVersion);
|
||||
} catch (const std::ios_base::failure& e) {
|
||||
} catch (const std::ios_base::failure&) {
|
||||
return;
|
||||
}
|
||||
bool valid = true;
|
||||
bool valid_tx = true;
|
||||
const CTransaction tx = [&] {
|
||||
try {
|
||||
return CTransaction(deserialize, ds);
|
||||
} catch (const std::ios_base::failure& e) {
|
||||
valid = false;
|
||||
} catch (const std::ios_base::failure&) {
|
||||
valid_tx = false;
|
||||
return CTransaction();
|
||||
}
|
||||
}();
|
||||
if (!valid) {
|
||||
bool valid_mutable_tx = true;
|
||||
CDataStream ds_mtx(buffer, SER_NETWORK, INIT_PROTO_VERSION);
|
||||
CMutableTransaction mutable_tx;
|
||||
try {
|
||||
int nVersion;
|
||||
ds_mtx >> nVersion;
|
||||
ds_mtx.SetVersion(nVersion);
|
||||
ds_mtx >> mutable_tx;
|
||||
} catch (const std::ios_base::failure&) {
|
||||
valid_mutable_tx = false;
|
||||
}
|
||||
assert(valid_tx == valid_mutable_tx);
|
||||
if (!valid_tx) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user