libwalletqt: fix potential out-of-bounds read
What changed, and why it matters
This commit fixes a bug in Feather Wallet's transaction handling code where reading a fee or mixin value could access memory outside the intended list if the list was empty. The old check used unsigned arithmetic that could wrap around when empty, making the guard ineffective. The new check explicitly handles empty lists and uses a safer comparison. This could have caused crashes or incorrect transaction data being read.
Review whether these functions are reachable from user-controlled input paths (e.g., transaction parsing or UI display), and consider adding regression tests for empty transaction vectors. The fix should be included in the next release.
Security signals we found
Out-of-bounds read due to unsigned integer underflow in bounds check
Undefined behavior on empty std::vector access
Fix present in commit title and diff
Evidence from the diff
In UnsignedTransaction::fee() and UnsignedTransaction::mixin(), the bounds check index > arr.size() - 1 is unsafe when arr is empty because arr.size() returns size_t (unsigned), so arr.size() - 1 underflows to SIZE_MAX. This makes the condition false, allowing arr[index] to be evaluated on an empty vector, resulting in undefined behavior (out-of-bounds read). The patch replaces this with arr.empty() || index >= arr.size(), which is correct for all cases including empty vectors.
Changed components
src/libwalletqt/UnsignedTransaction.cppUnsignedTransaction::fee()UnsignedTransaction::mixin()Inspect captured patch +2 / −2
### src/libwalletqt/UnsignedTransaction.cpp
@@ -27,15 +27,15 @@ quint64 UnsignedTransaction::amount(size_t index) const
quint64 UnsignedTransaction::fee(size_t index) const
{
std::vector<uint64_t> arr = m_pimpl->fee();
- if(index > arr.size() - 1)
+ if(arr.empty() || index >= arr.size())
return 0;
return arr[index];
}
quint64 UnsignedTransaction::mixin(size_t index) const
{
std::vector<uint64_t> arr = m_pimpl->mixin();
- if(index > arr.size() - 1)
+ if(arr.empty() || index >= arr.size())
return 0;
return arr[index];
}Why this scored 44/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.