mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Merge bitcoin/bitcoin#28873: fuzz: AutoFile with XOR
faa25718b3fuzz: AutoFile with XOR (MarcoFalke)fab5cb9066fuzz: Reduce LIMITED_WHILE limit for file fuzzing (MarcoFalke)fa5388fad3fuzz: Remove FuzzedAutoFileProvider (MarcoFalke) Pull request description: This should help to get fuzz coverage for https://maflcko.github.io/b-c-cov/fuzz.coverage/src/streams.cpp.gcov.html Also, remove unused code and fix a timeout bug. ACKs for top commit: dergoegge: ACKfaa25718b3Tree-SHA512: 56f1e6fd5cb2b66ffd9a7d9c09c9b8e396be3e7485feb03b35b6bd3c48e624fdaed50b472e4ffec21f09efb5e949d7ee32a13851849c9140b6b4cf25917dd7ac
This commit is contained in:
@@ -2,24 +2,28 @@
|
|||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <span.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <cstdint>
|
#include <cstddef>
|
||||||
|
#include <cstdio>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <optional>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
FUZZ_TARGET(autofile)
|
FUZZ_TARGET(autofile)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||||
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
|
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
|
||||||
AutoFile auto_file{fuzzed_auto_file_provider.open()};
|
AutoFile auto_file{
|
||||||
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
|
fuzzed_file_provider.open(),
|
||||||
|
ConsumeRandomLengthByteVector<std::byte>(fuzzed_data_provider),
|
||||||
|
};
|
||||||
|
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100)
|
||||||
|
{
|
||||||
CallOneOf(
|
CallOneOf(
|
||||||
fuzzed_data_provider,
|
fuzzed_data_provider,
|
||||||
[&] {
|
[&] {
|
||||||
|
|||||||
@@ -2,31 +2,37 @@
|
|||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <span.h>
|
||||||
#include <streams.h>
|
#include <streams.h>
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
FUZZ_TARGET(buffered_file)
|
FUZZ_TARGET(buffered_file)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||||
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
|
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
|
||||||
std::optional<BufferedFile> opt_buffered_file;
|
std::optional<BufferedFile> opt_buffered_file;
|
||||||
CAutoFile fuzzed_file{fuzzed_file_provider.open(), 0};
|
CAutoFile fuzzed_file{
|
||||||
|
fuzzed_file_provider.open(),
|
||||||
|
0,
|
||||||
|
ConsumeRandomLengthByteVector<std::byte>(fuzzed_data_provider),
|
||||||
|
};
|
||||||
try {
|
try {
|
||||||
opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096));
|
opt_buffered_file.emplace(fuzzed_file, fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096), fuzzed_data_provider.ConsumeIntegralInRange<uint64_t>(0, 4096));
|
||||||
} catch (const std::ios_base::failure&) {
|
} catch (const std::ios_base::failure&) {
|
||||||
}
|
}
|
||||||
if (opt_buffered_file && !fuzzed_file.IsNull()) {
|
if (opt_buffered_file && !fuzzed_file.IsNull()) {
|
||||||
bool setpos_fail = false;
|
bool setpos_fail = false;
|
||||||
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
|
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100)
|
||||||
|
{
|
||||||
CallOneOf(
|
CallOneOf(
|
||||||
fuzzed_data_provider,
|
fuzzed_data_provider,
|
||||||
[&] {
|
[&] {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ void initialize_load_external_block_file()
|
|||||||
FUZZ_TARGET(load_external_block_file, .init = initialize_load_external_block_file)
|
FUZZ_TARGET(load_external_block_file, .init = initialize_load_external_block_file)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||||
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
|
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
|
||||||
CAutoFile fuzzed_block_file{fuzzed_file_provider.open(), CLIENT_VERSION};
|
CAutoFile fuzzed_block_file{fuzzed_file_provider.open(), CLIENT_VERSION};
|
||||||
if (fuzzed_block_file.IsNull()) {
|
if (fuzzed_block_file.IsNull()) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <test/fuzz/util/mempool.h>
|
#include <test/fuzz/util/mempool.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -81,8 +82,8 @@ FUZZ_TARGET(policy_estimator, .init = initialize_policy_estimator)
|
|||||||
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
|
(void)block_policy_estimator.HighestTargetTracked(fuzzed_data_provider.PickValueInArray(ALL_FEE_ESTIMATE_HORIZONS));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
|
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
|
||||||
AutoFile fuzzed_auto_file{fuzzed_auto_file_provider.open()};
|
AutoFile fuzzed_auto_file{fuzzed_file_provider.open()};
|
||||||
block_policy_estimator.Write(fuzzed_auto_file);
|
block_policy_estimator.Write(fuzzed_auto_file);
|
||||||
block_policy_estimator.Read(fuzzed_auto_file);
|
block_policy_estimator.Read(fuzzed_auto_file);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <policy/fees_args.h>
|
#include <policy/fees_args.h>
|
||||||
|
#include <streams.h>
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/fuzz/util.h>
|
#include <test/fuzz/util.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <memory>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const BasicTestingSetup* g_setup;
|
const BasicTestingSetup* g_setup;
|
||||||
@@ -25,8 +25,8 @@ void initialize_policy_estimator_io()
|
|||||||
FUZZ_TARGET(policy_estimator_io, .init = initialize_policy_estimator_io)
|
FUZZ_TARGET(policy_estimator_io, .init = initialize_policy_estimator_io)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
|
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
|
||||||
AutoFile fuzzed_auto_file{fuzzed_auto_file_provider.open()};
|
AutoFile fuzzed_auto_file{fuzzed_file_provider.open()};
|
||||||
// Re-using block_policy_estimator across runs to avoid costly creation of CBlockPolicyEstimator object.
|
// Re-using block_policy_estimator across runs to avoid costly creation of CBlockPolicyEstimator object.
|
||||||
static CBlockPolicyEstimator block_policy_estimator{FeeestPath(*g_setup->m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES};
|
static CBlockPolicyEstimator block_policy_estimator{FeeestPath(*g_setup->m_node.args), DEFAULT_ACCEPT_STALE_FEE_ESTIMATES};
|
||||||
if (block_policy_estimator.Read(fuzzed_auto_file)) {
|
if (block_policy_estimator.Read(fuzzed_auto_file)) {
|
||||||
|
|||||||
@@ -263,31 +263,6 @@ public:
|
|||||||
static int close(void* cookie);
|
static int close(void* cookie);
|
||||||
};
|
};
|
||||||
|
|
||||||
[[nodiscard]] inline FuzzedFileProvider ConsumeFile(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
|
||||||
{
|
|
||||||
return {fuzzed_data_provider};
|
|
||||||
}
|
|
||||||
|
|
||||||
class FuzzedAutoFileProvider
|
|
||||||
{
|
|
||||||
FuzzedFileProvider m_fuzzed_file_provider;
|
|
||||||
|
|
||||||
public:
|
|
||||||
FuzzedAutoFileProvider(FuzzedDataProvider& fuzzed_data_provider) : m_fuzzed_file_provider{fuzzed_data_provider}
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoFile open()
|
|
||||||
{
|
|
||||||
return AutoFile{m_fuzzed_file_provider.open()};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
[[nodiscard]] inline FuzzedAutoFileProvider ConsumeAutoFile(FuzzedDataProvider& fuzzed_data_provider) noexcept
|
|
||||||
{
|
|
||||||
return {fuzzed_data_provider};
|
|
||||||
}
|
|
||||||
|
|
||||||
#define WRITE_TO_STREAM_CASE(type, consume) \
|
#define WRITE_TO_STREAM_CASE(type, consume) \
|
||||||
[&] { \
|
[&] { \
|
||||||
type o = consume; \
|
type o = consume; \
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ FUZZ_TARGET(validation_load_mempool, .init = initialize_validation_load_mempool)
|
|||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||||
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
SetMockTime(ConsumeTime(fuzzed_data_provider));
|
||||||
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
|
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
|
||||||
|
|
||||||
CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node)};
|
CTxMemPool pool{MemPoolOptionsForTest(g_setup->m_node)};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user