aboutsummaryrefslogtreecommitdiff
path: root/src/zenstore/filecas.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2024-04-03 17:50:48 +0200
committerGitHub Enterprise <[email protected]>2024-04-03 17:50:48 +0200
commit4e328366efc3a2cccd286a7e191663af24dfe50d (patch)
tree931d259180bb7f54a926b5e5b46867cd7eeb4675 /src/zenstore/filecas.cpp
parentzenremoteprojectstore with httpclient (#35) (diff)
downloadzen-4e328366efc3a2cccd286a7e191663af24dfe50d.tar.xz
zen-4e328366efc3a2cccd286a7e191663af24dfe50d.zip
validate rpc chunk responses (#36)
* Validate size of found chunks in cas/cache
Diffstat (limited to 'src/zenstore/filecas.cpp')
-rw-r--r--src/zenstore/filecas.cpp17
1 files changed, 13 insertions, 4 deletions
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