Skip to content

Commit d248417

Browse files
committed
fix: prevent integer underflow in amount() bounds check
The bounds check 'index > arr.size() - 1' has an edge case bug. When arr.size() is 0, subtracting 1 from an unsigned size_t underflows to SIZE_MAX, so 'index > SIZE_MAX' is always false. This could theoretically allow out-of-bounds access, though it's pretty hard to trigger in practice - would need a malformed/corrupted unsigned_tx file that parses successfully but has no transactions. Changed to 'arr.empty() || index >= arr.size()' which handles the edge case properly. Found with AddressSanitizer during fuzzing.
1 parent 42dc35d commit d248417

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/libwalletqt/UnsignedTransaction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ QString UnsignedTransaction::errorString() const
1919
quint64 UnsignedTransaction::amount(size_t index) const
2020
{
2121
std::vector<uint64_t> arr = m_pimpl->amount();
22-
if(index > arr.size() - 1)
22+
if(arr.empty() || index >= arr.size())
2323
return 0;
2424
return arr[index];
2525
}

0 commit comments

Comments
 (0)