From 4e328366efc3a2cccd286a7e191663af24dfe50d Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Wed, 3 Apr 2024 17:50:48 +0200 Subject: validate rpc chunk responses (#36) * Validate size of found chunks in cas/cache --- src/zenstore/filecas.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'src/zenstore/filecas.cpp') diff --git a/src/zenstore/filecas.cpp b/src/zenstore/filecas.cpp index 428183827..6b4185ff4 100644 --- a/src/zenstore/filecas.cpp +++ b/src/zenstore/filecas.cpp @@ -729,19 +729,28 @@ FileCasStrategy::FindChunk(const IoHash& ChunkHash) ZEN_ASSERT(m_IsInitialized); + uint64_t ExpectedSize = 0; { RwLock::SharedLockScope _(m_Lock); - if (!m_Index.contains(ChunkHash)) + if (auto It = m_Index.find(ChunkHash); It != m_Index.end()) + { + ExpectedSize = It->second.Size; + } + else { return {}; } } - ShardingHelper Name(m_RootDirectory.c_str(), ChunkHash); - + ShardingHelper Name(m_RootDirectory.c_str(), ChunkHash); RwLock::SharedLockScope _(LockForHash(ChunkHash)); - return IoBufferBuilder::MakeFromFile(Name.ShardedPath.c_str()); + if (IoBuffer Chunk = IoBufferBuilder::MakeFromFile(Name.ShardedPath.c_str()); Chunk.GetSize() == ExpectedSize) + { + return Chunk; + } + + return {}; } bool -- cgit v1.2.3