-
Notifications
You must be signed in to change notification settings - Fork 769
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add fuzzing harness for serialization/deserialization of float…
…ing-points and integrals Summary: ``` Add simple fuzzing harness for functions with floating-point parameters (such as ser_double_to_uint64(double), etc.). Add serialization/deserialization fuzzing for integral types. ``` Backport of core [[bitcoin/bitcoin#17996 | PR17996]]. The first and last commit are not relevant to us. Test Plan: ninja bitcoin-fuzzers ./test/fuzz/test_runner.py <path_to_corpus> Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D8249
- Loading branch information
1 parent
5a1a1b1
commit b8598eb
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ add_regular_fuzz_targets( | |
cashaddr | ||
descriptor_parse | ||
eval_script | ||
float | ||
hex | ||
integer | ||
net_permissions | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) 2020 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <memusage.h> | ||
#include <serialize.h> | ||
#include <streams.h> | ||
#include <version.h> | ||
|
||
#include <test/fuzz/FuzzedDataProvider.h> | ||
#include <test/fuzz/fuzz.h> | ||
|
||
#include <cassert> | ||
#include <cstdint> | ||
|
||
void test_one_input(const std::vector<uint8_t> &buffer) { | ||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); | ||
|
||
{ | ||
const double d = fuzzed_data_provider.ConsumeFloatingPoint<double>(); | ||
(void)memusage::DynamicUsage(d); | ||
assert(ser_uint64_to_double(ser_double_to_uint64(d)) == d); | ||
|
||
CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION); | ||
stream << d; | ||
double d_deserialized; | ||
stream >> d_deserialized; | ||
assert(d == d_deserialized); | ||
} | ||
|
||
{ | ||
const float f = fuzzed_data_provider.ConsumeFloatingPoint<float>(); | ||
(void)memusage::DynamicUsage(f); | ||
assert(ser_uint32_to_float(ser_float_to_uint32(f)) == f); | ||
|
||
CDataStream stream(SER_NETWORK, INIT_PROTO_VERSION); | ||
stream << f; | ||
float f_deserialized; | ||
stream >> f_deserialized; | ||
assert(f == f_deserialized); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters