wallet2: clamp export_outputs start to the number of transfers

export_outputs() says start and count are allowed to go past the valid range,
and that nothing is returned when they do. The loop honours that, but offset
does not: with all=true it takes start unchecked, so a start past the end makes
m_transfers.size() - offset underflow and reserve() gets a value near SIZE_MAX.
vector::reserve throws std::length_error on that, which is where the
"vector::reserve" error in issue #8625 comes from.

Clamping offset also keeps the returned offset usable. import_outputs throws
when offset is past the total, so leaving offset at start would only move the
failure from export to import.
This commit is contained in:
Cole Munz
2026-07-31 23:41:03 -05:00
parent ae3931c1d9
commit a646d9e7c3
+1 -1
View File
@@ -14014,7 +14014,7 @@ std::tuple<uint64_t, uint64_t, std::vector<tools::wallet2::exported_transfer_det
while (offset < m_transfers.size() && (m_transfers[offset].m_key_image_known && !m_transfers[offset].m_key_image_request))
++offset;
else
offset = start;
offset = std::min<size_t>(start, m_transfers.size());
outs.reserve(m_transfers.size() - offset);
for (size_t n = offset; n < m_transfers.size() && n - offset < count; ++n)