File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ FUZZ_TARGETS = \
98
98
test/fuzz/string \
99
99
test/fuzz/strprintf \
100
100
test/fuzz/sub_net_deserialize \
101
+ test/fuzz/timedata \
101
102
test/fuzz/transaction \
102
103
test/fuzz/tx_in \
103
104
test/fuzz/tx_in_deserialize \
@@ -853,6 +854,12 @@ test_fuzz_sub_net_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
853
854
test_fuzz_sub_net_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
854
855
test_fuzz_sub_net_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
855
856
857
+ test_fuzz_timedata_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
858
+ test_fuzz_timedata_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
859
+ test_fuzz_timedata_LDADD = $(FUZZ_SUITE_LD_COMMON)
860
+ test_fuzz_timedata_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
861
+ test_fuzz_timedata_SOURCES = $(FUZZ_SUITE) test/fuzz/timedata.cpp
862
+
856
863
test_fuzz_transaction_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
857
864
test_fuzz_transaction_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
858
865
test_fuzz_transaction_LDADD = $(FUZZ_SUITE_LD_COMMON)
Original file line number Diff line number Diff line change
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 < test/fuzz/FuzzedDataProvider.h>
6
+ #include < test/fuzz/fuzz.h>
7
+ #include < test/fuzz/util.h>
8
+ #include < timedata.h>
9
+
10
+ #include < cstdint>
11
+ #include < string>
12
+ #include < vector>
13
+
14
+ void test_one_input (const std::vector<uint8_t >& buffer)
15
+ {
16
+ FuzzedDataProvider fuzzed_data_provider (buffer.data (), buffer.size ());
17
+ const unsigned int max_size = fuzzed_data_provider.ConsumeIntegralInRange <unsigned int >(0 , 1000 );
18
+ // Divide by 2 to avoid signed integer overflow in .median()
19
+ const int64_t initial_value = fuzzed_data_provider.ConsumeIntegral <int64_t >() / 2 ;
20
+ CMedianFilter<int64_t > median_filter{max_size, initial_value};
21
+ while (fuzzed_data_provider.remaining_bytes () > 0 ) {
22
+ (void )median_filter.median ();
23
+ assert (median_filter.size () > 0 );
24
+ assert (static_cast <size_t >(median_filter.size ()) == median_filter.sorted ().size ());
25
+ assert (static_cast <unsigned int >(median_filter.size ()) <= max_size || max_size == 0 );
26
+ // Divide by 2 to avoid signed integer overflow in .median()
27
+ median_filter.input (fuzzed_data_provider.ConsumeIntegral <int64_t >() / 2 );
28
+ }
29
+ }
You can’t perform that action at this time.
0 commit comments