Skip to content

Commit 7bcc71e

Browse files
tests: Add fuzzing harness for LoadExternalBlockFile(...) (validation.h)
1 parent 9823376 commit 7bcc71e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Makefile.test.include

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ FUZZ_TARGETS = \
5757
test/fuzz/key_io \
5858
test/fuzz/key_origin_info_deserialize \
5959
test/fuzz/kitchen_sink \
60+
test/fuzz/load_external_block_file \
6061
test/fuzz/locale \
6162
test/fuzz/merkle_block_deserialize \
6263
test/fuzz/merkleblock \
@@ -634,6 +635,12 @@ test_fuzz_kitchen_sink_LDADD = $(FUZZ_SUITE_LD_COMMON)
634635
test_fuzz_kitchen_sink_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
635636
test_fuzz_kitchen_sink_SOURCES = test/fuzz/kitchen_sink.cpp
636637

638+
test_fuzz_load_external_block_file_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
639+
test_fuzz_load_external_block_file_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
640+
test_fuzz_load_external_block_file_LDADD = $(FUZZ_SUITE_LD_COMMON)
641+
test_fuzz_load_external_block_file_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
642+
test_fuzz_load_external_block_file_SOURCES = test/fuzz/load_external_block_file.cpp
643+
637644
test_fuzz_locale_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
638645
test_fuzz_locale_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
639646
test_fuzz_locale_LDADD = $(FUZZ_SUITE_LD_COMMON)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <chainparams.h>
6+
#include <flatfile.h>
7+
#include <test/fuzz/FuzzedDataProvider.h>
8+
#include <test/fuzz/fuzz.h>
9+
#include <test/fuzz/util.h>
10+
#include <test/util/setup_common.h>
11+
#include <validation.h>
12+
13+
#include <cstdint>
14+
#include <vector>
15+
16+
void initialize()
17+
{
18+
InitializeFuzzingContext();
19+
}
20+
21+
void test_one_input(const std::vector<uint8_t>& buffer)
22+
{
23+
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
24+
FuzzedFileProvider fuzzed_file_provider = ConsumeFile(fuzzed_data_provider);
25+
FILE* fuzzed_block_file = fuzzed_file_provider.open();
26+
if (fuzzed_block_file == nullptr) {
27+
return;
28+
}
29+
FlatFilePos flat_file_pos;
30+
LoadExternalBlockFile(Params(), fuzzed_block_file, fuzzed_data_provider.ConsumeBool() ? &flat_file_pos : nullptr);
31+
}

0 commit comments

Comments
 (0)