Skip to content

Commit 2bcc2bd

Browse files
tests: Clarify how we avoid hitting the signed integer overflow in CFeeRate::GetFeePerK() when fuzzing
1 parent 13c1f6b commit 2bcc2bd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/test/fuzz/util.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ NODISCARD inline CTxMemPoolEntry ConsumeTxMemPoolEntry(FuzzedDataProvider& fuzze
104104
{
105105
// Avoid:
106106
// policy/feerate.cpp:28:34: runtime error: signed integer overflow: 34873208148477500 * 1000 cannot be represented in type 'long'
107-
const CAmount fee = ConsumeMoney(fuzzed_data_provider) / static_cast<CAmount>(100);
107+
//
108+
// Reproduce using CFeeRate(348732081484775, 10).GetFeePerK()
109+
const CAmount fee = std::min<CAmount>(ConsumeMoney(fuzzed_data_provider), std::numeric_limits<CAmount>::max() / static_cast<CAmount>(100000));
110+
assert(MoneyRange(fee));
108111
const int64_t time = fuzzed_data_provider.ConsumeIntegral<int64_t>();
109112
const unsigned int entry_height = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
110113
const bool spends_coinbase = fuzzed_data_provider.ConsumeBool();

0 commit comments

Comments
 (0)