Merge #17996: tests: Add fuzzing harness for serialization/deserialization of floating-points and integrals
pull/764/head9ff41f6419
tests: Add float to FUZZERS_MISSING_CORPORA (temporarily) (practicalswift)8f6fb0a85a
tests: Add serialization/deserialization fuzzing for integral types (practicalswift)3c82b92d2e
tests: Add fuzzing harness for functions taking floating-point types as input (practicalswift)c2bd588860
Add missing includes (practicalswift) Pull request description: 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. Add missing includes. To test this PR: ``` $ make distclean $ ./autogen.sh $ CC=clang CXX=clang++ ./configure --enable-fuzz \ --with-sanitizers=address,fuzzer,undefined $ make $ src/test/fuzz/float … ``` Top commit has no ACKs. Tree-SHA512: 9b5a0c4838ad18d715c7398e557d2a6d0fcc03aa842f76d7a8ed716170a28f17f249eaede4256998aa3417afe2935e0ffdfaa883727d71ae2d2d18a41ced24b5
commit
a2b5aae9f3
@ -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 <test/fuzz/FuzzedDataProvider.h>
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <version.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);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue