blockchain_utilities: fix memory safety bugs

This commit is contained in:
jpk68
2026-08-25 14:58:24 -04:00
parent 24c2dd987a
commit 772d856605
2 changed files with 7 additions and 2 deletions
@@ -39,6 +39,7 @@
#include "cryptonote_basic/cryptonote_boost_serialization.h"
#include "cryptonote_core/cryptonote_core.h"
#include "version.h"
#include "misc_log_ex.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "bcutil"
@@ -158,7 +159,11 @@ struct ancestry_state_t
{
std::unordered_map<uint64_t, cryptonote::block> old_block_cache;
a & old_block_cache;
block_cache.resize(old_block_cache.size());
uint64_t max_height = 0;
for (const auto& i: old_block_cache)
max_height = std::max(max_height, i.first);
CHECK_AND_ASSERT_THROW_MES(old_block_cache.empty() || max_height < block_cache.max_size(), "Corrupt ancestry state: block height too large");
block_cache.resize(old_block_cache.empty() ? 0 : max_height + 1);
for (const auto& i: old_block_cache)
block_cache[i.first] = i.second;
}
@@ -334,7 +334,7 @@ plot 'stats.csv' index "DATA" using (timecolumn(1,"%Y-%m-%d")):4 with lines, ''
maxins = io;
totins += io;
}
if (do_ringsize) {
if (do_ringsize && !tx.vin.empty() && tx.vin[0].type() == typeid(cryptonote::txin_to_key)) {
const cryptonote::txin_to_key& tx_in_to_key
= boost::get<cryptonote::txin_to_key>(tx.vin[0]);
io = tx_in_to_key.key_offsets.size();