fix: prevent integer underflow in amount() bounds check
What changed, and why it matters
A single-line fix in Feather Wallet's unsigned-transaction handling corrects a bounds check that could fail when a transaction list is empty. The old check accidentally turned into 'always pass' for empty lists due to an unsigned integer underflow, which could let the program read past the end of an empty array and return garbage or crash. The fix makes the empty case explicit. The commit notes this was found by automated fuzzing and would require a malformed unsigned transaction file to trigger.
Apply the patch. Consider adding a regression unit test that calls amount(0) on an empty UnsignedTransaction and verify it returns 0 without sanitizer errors. Review nearby index/size_t arithmetic for similar patterns.
Security signals we found
Integer underflow in unsigned size_t arithmetic
Missing bounds check on zero-length container
Out-of-bounds read potential
Found via AddressSanitizer fuzzing
Evidence from the diff
In UnsignedTransaction::amount(size_t index), the original guard ‘index > arr.size() - 1’ underflows when arr.size() == 0 because size_t is unsigned, producing index > SIZE_MAX (always false). This removes bounds protection on an empty vector and permits an out-of-bounds read at arr[index]. The patch replaces it with ‘arr.empty() || index >= arr.size()’, which is safe for empty and non-empty vectors. The function returns 0 on a failed check, so the practical effect is likely a controlled bad value rather than an arbitrary memory corruption primitive.
Changed components
src/libwalletqt/UnsignedTransaction.cppUnsignedTransaction::amount(size_t index)Inspect captured patch +1 / −1
diff --git a/src/libwalletqt/UnsignedTransaction.cpp b/src/libwalletqt/UnsignedTransaction.cpp
index 02206dd..8eef425 100644
--- a/src/libwalletqt/UnsignedTransaction.cpp
+++ b/src/libwalletqt/UnsignedTransaction.cpp
@@ -19,7 +19,7 @@ QString UnsignedTransaction::errorString() const
quint64 UnsignedTransaction::amount(size_t index) const
{
std::vector<uint64_t> arr = m_pimpl->amount();
- if(index > arr.size() - 1)
+ if(arr.empty() || index >= arr.size())
return 0;
return arr[index];
}
Why this scored 45/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.