Skip to content

Commit 3b317db

Browse files
MarcoFalkePastaPastaPasta
authored andcommitted
Merge bitcoin#22454: fuzz: Limit max ops in tx_pool fuzz targets
fa33ed4 fuzz: Limit max ops in tx_pool fuzz targets (MarcoFalke) Pull request description: Without a size limit on the input data, the runtime is unbounded. Fix this by picking an upper bound on the maximum number of fuzz operations. Reproducer from OSS-Fuzz (without bug report): [clusterfuzz-testcase-tx_pool_standard-5963992253202432.log](https://github.com/bitcoin/bitcoin/files/6822465/clusterfuzz-testcase-tx_pool_standard-5963992253202432.log) ACKs for top commit: practicalswift: cr ACK fa33ed4 Tree-SHA512: 32098d573880afba12d510ac83519dc886a6c65d5207edb810f92c7c61edf5e2fc9c57e7b7a1ae656c02ce14e3595707dd6b93caf7956beb2bc817609e14d23d
1 parent 14a24ac commit 3b317db

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/test/fuzz/tx_pool.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ void SetMempoolConstraints(ArgsManager& args, FuzzedDataProvider& fuzzed_data_pr
7878

7979
FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
8080
{
81+
// Pick an arbitrary upper bound to limit the runtime and avoid timeouts on
82+
// inputs.
83+
int limit_max_ops{300};
84+
8185
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
8286
const auto& node = g_setup->m_node;
8387
auto& chainstate = node.chainman->ActiveChainstate();
@@ -108,7 +112,7 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
108112
return c.out.nValue;
109113
};
110114

111-
while (fuzzed_data_provider.ConsumeBool()) {
115+
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) {
112116
{
113117
// Total supply is all outpoints
114118
CAmount supply_now{0};
@@ -259,6 +263,10 @@ FUZZ_TARGET_INIT(tx_pool_standard, initialize_tx_pool)
259263

260264
FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
261265
{
266+
// Pick an arbitrary upper bound to limit the runtime and avoid timeouts on
267+
// inputs.
268+
int limit_max_ops{300};
269+
262270
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
263271
const auto& node = g_setup->m_node;
264272

@@ -274,7 +282,7 @@ FUZZ_TARGET_INIT(tx_pool, initialize_tx_pool)
274282

275283
CTxMemPool tx_pool{/* estimator */ nullptr, /* check_ratio */ 1};
276284

277-
while (fuzzed_data_provider.ConsumeBool()) {
285+
while (--limit_max_ops >= 0 && fuzzed_data_provider.ConsumeBool()) {
278286
const auto mut_tx = ConsumeTransaction(fuzzed_data_provider, txids);
279287

280288
const auto tx = MakeTransactionRef(mut_tx);

0 commit comments

Comments
 (0)