mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 12:09:54 +00:00
blockchain: sanity check number of precomputed hash of hash blocks
Coverity 142951
This commit is contained in:
parent
9af6b2d1b8
commit
61defd89e3
1 changed files with 6 additions and 1 deletions
|
@ -4343,8 +4343,13 @@ void Blockchain::load_compiled_in_block_hashes()
|
||||||
{
|
{
|
||||||
const unsigned char *p = get_blocks_dat_start(m_testnet);
|
const unsigned char *p = get_blocks_dat_start(m_testnet);
|
||||||
const uint32_t nblocks = *p | ((*(p+1))<<8) | ((*(p+2))<<16) | ((*(p+3))<<24);
|
const uint32_t nblocks = *p | ((*(p+1))<<8) | ((*(p+2))<<16) | ((*(p+3))<<24);
|
||||||
|
if (nblocks > (std::numeric_limits<uint32_t>::max() - 4) / sizeof(hash))
|
||||||
|
{
|
||||||
|
MERROR("Block hash data is too large");
|
||||||
|
return;
|
||||||
|
}
|
||||||
const size_t size_needed = 4 + nblocks * sizeof(crypto::hash);
|
const size_t size_needed = 4 + nblocks * sizeof(crypto::hash);
|
||||||
if(nblocks > 0 && nblocks * HASH_OF_HASHES_STEP > m_db->height() && get_blocks_dat_size(m_testnet) >= size_needed)
|
if(nblocks > 0 && nblocks > (m_db->height() + HASH_OF_HASHES_STEP - 1) / HASH_OF_HASHES_STEP && get_blocks_dat_size(m_testnet) >= size_needed)
|
||||||
{
|
{
|
||||||
p += sizeof(uint32_t);
|
p += sizeof(uint32_t);
|
||||||
m_blocks_hash_of_hashes.reserve(nblocks);
|
m_blocks_hash_of_hashes.reserve(nblocks);
|
||||||
|
|
Loading…
Reference in a new issue