From afca83d6c2e047cafbab475729f910b58e593ab4 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Fri, 27 Aug 2021 10:37:14 +0200 Subject: [PATCH] BlockCache: check block size before storing it --- src/block_cache.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/block_cache.cpp b/src/block_cache.cpp index 2199599..2aaa87d 100644 --- a/src/block_cache.cpp +++ b/src/block_cache.cpp @@ -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(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(data) = static_cast(n1 + n2); memcpy(data + sizeof(uint32_t), block.m_mainChainData.data(), n1); memcpy(data + sizeof(uint32_t) + n1, block.m_sideChainData.data(), n2);