Skip to content

Commit 67c8aac

Browse files
committed
Guard multisig::put_ref::count() (vs. assert).
1 parent 4fa75cd commit 67c8aac

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

include/bitcoin/database/tables/caches/multisig.hpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,19 @@ struct multisig
8787
using namespace system;
8888
const auto m = sigs.size();
8989
const auto n = keys.size();
90+
if (is_subtract_overflow(n, m))
91+
return {};
9092

91-
BC_ASSERT(!is_subtract_overflow(n, m));
92-
BC_ASSERT(!is_add_overflow(n - m, one));
93-
BC_ASSERT(!is_multiply_overflow(m, add1(n - m)));
94-
return possible_narrow_cast<link::integer>(m * add1(n - m));
93+
const auto gap = n - m;
94+
if (is_add_overflow(gap, one))
95+
return {};
96+
97+
const auto sum = add1(gap);
98+
if (is_multiply_overflow(m, sum))
99+
return {};
100+
101+
// Terminal count fails the write attempt, so to_data() is guarded.
102+
return possible_narrow_cast<link::integer>(m * sum);
95103
}
96104

97105
inline bool to_data(flipper& sink) const NOEXCEPT

0 commit comments

Comments
 (0)