Merge pull request #10728

af10a4f read import blob crypto fields with memcpy in wallet2 (alhudz)
This commit is contained in:
tobtoht
2026-06-11 20:26:05 +00:00
+14 -9
View File
@@ -13169,8 +13169,9 @@ uint64_t wallet2::import_key_images(const std::string &filename, uint64_t &spent
const size_t headerlen = 4 + 2 * sizeof(crypto::public_key);
THROW_WALLET_EXCEPTION_IF(data.size() < headerlen, error::wallet_internal_error, std::string("Bad data size from file ") + filename);
const uint32_t offset = (uint8_t)data[0] | (((uint8_t)data[1]) << 8) | (((uint8_t)data[2]) << 16) | (((uint8_t)data[3]) << 24);
const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[4];
const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[4 + sizeof(crypto::public_key)];
crypto::public_key public_spend_key, public_view_key;
memcpy(&public_spend_key, &data[4], sizeof(public_spend_key));
memcpy(&public_view_key, &data[4 + sizeof(crypto::public_key)], sizeof(public_view_key));
const cryptonote::account_public_address &keys = get_account().get_keys().m_account_address;
if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
{
@@ -13187,8 +13188,10 @@ uint64_t wallet2::import_key_images(const std::string &filename, uint64_t &spent
ski.reserve(nki);
for (size_t n = 0; n < nki; ++n)
{
crypto::key_image key_image = *reinterpret_cast<const crypto::key_image*>(&data[headerlen + n * record_size]);
crypto::signature signature = *reinterpret_cast<const crypto::signature*>(&data[headerlen + n * record_size + sizeof(crypto::key_image)]);
crypto::key_image key_image;
crypto::signature signature;
memcpy(&key_image, &data[headerlen + n * record_size], sizeof(key_image));
memcpy(&signature, &data[headerlen + n * record_size + sizeof(crypto::key_image)], sizeof(signature));
ski.push_back(std::make_pair(key_image, signature));
}
@@ -14255,8 +14258,9 @@ size_t wallet2::import_outputs_from_str(const std::string &outputs_st)
{
THROW_WALLET_EXCEPTION(error::wallet_internal_error, std::string("Bad data size for outputs"));
}
const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[0];
const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[sizeof(crypto::public_key)];
crypto::public_key public_spend_key, public_view_key;
memcpy(&public_spend_key, &data[0], sizeof(public_spend_key));
memcpy(&public_view_key, &data[sizeof(crypto::public_key)], sizeof(public_view_key));
const cryptonote::account_public_address &keys = get_account().get_keys().m_account_address;
if (public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key)
{
@@ -14601,9 +14605,10 @@ size_t wallet2::import_multisig(std::vector<cryptonote::blobdata> blobs, bool re
const size_t headerlen = 3 * sizeof(crypto::public_key);
THROW_WALLET_EXCEPTION_IF(data.size() < headerlen, error::wallet_internal_error, "Bad data size");
const crypto::public_key &public_spend_key = *(const crypto::public_key*)&data[0];
const crypto::public_key &public_view_key = *(const crypto::public_key*)&data[sizeof(crypto::public_key)];
const crypto::public_key &signer = *(const crypto::public_key*)&data[2*sizeof(crypto::public_key)];
crypto::public_key public_spend_key, public_view_key, signer;
memcpy(&public_spend_key, &data[0], sizeof(public_spend_key));
memcpy(&public_view_key, &data[sizeof(crypto::public_key)], sizeof(public_view_key));
memcpy(&signer, &data[2*sizeof(crypto::public_key)], sizeof(signer));
const cryptonote::account_public_address &keys = get_account().get_keys().m_account_address;
THROW_WALLET_EXCEPTION_IF(public_spend_key != keys.m_spend_public_key || public_view_key != keys.m_view_public_key,
error::wallet_internal_error, "Multisig info is for a different account");