Skip to content

Commit 56d878c

Browse files
darosiormarcofleon
authored andcommitted
fuzz: avoid underflow in coins_view target
1 parent 2df824f commit 56d878c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/test/fuzz/coins_view.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ FUZZ_TARGET(coins_view, .init = initialize_coins_view)
6969
if (e.what() == std::string{"Attempted to overwrite an unspent coin (when possible_overwrite is false)"}) {
7070
assert(!possible_overwrite);
7171
expected_code_path = true;
72+
// AddCoin() decreases cachedCoinsUsage by the memory usage of the old coin at the beginning and
73+
// increases it by the value of the new coin at the end. If it throws in the process, the value
74+
// of cachedCoinsUsage would have been incorrectly decreased, leading to an underflow later on.
75+
// To avoid this, use Flush() to reset the value of cachedCoinsUsage in sync with the cacheCoins
76+
// mapping.
77+
(void)coins_view_cache.Flush();
7278
}
7379
}
7480
assert(expected_code_path);

0 commit comments

Comments
 (0)