BlockCache: check block size before storing it

This commit is contained in:
SChernykh 2021-08-27 10:37:14 +02:00
parent 2761ce5af7
commit afca83d6c2

View file

@ -164,15 +164,15 @@ BlockCache::~BlockCache()
void BlockCache::store(const PoolBlock& block)
{
if (!m_impl->m_data) {
const size_t n1 = block.m_mainChainData.size();
const size_t n2 = block.m_sideChainData.size();
if (!m_impl->m_data || (sizeof(uint32_t) + n1 + n2 > BLOCK_SIZE)) {
return;
}
uint8_t* data = m_impl->m_data + (static_cast<size_t>(block.m_sidechainHeight % NUM_BLOCKS) * BLOCK_SIZE);
const size_t n1 = block.m_mainChainData.size();
const size_t n2 = block.m_sideChainData.size();
*reinterpret_cast<uint32_t*>(data) = static_cast<uint32_t>(n1 + n2);
memcpy(data + sizeof(uint32_t), block.m_mainChainData.data(), n1);
memcpy(data + sizeof(uint32_t) + n1, block.m_sideChainData.data(), n2);