diff options
| author | Stefan Boberg <[email protected]> | 2021-09-16 13:11:11 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-16 13:11:25 +0200 |
| commit | 1983dc5f3292afa0b1b2b991428a91f111d34b8c (patch) | |
| tree | 16989f2d7a335ee67e121b452676d8919c3c1b61 /zenserver/compute/apply.cpp | |
| parent | Fixed misleading comment for `CbAttachment::AsCompositeBinary` (diff) | |
| download | zen-1983dc5f3292afa0b1b2b991428a91f111d34b8c.tar.xz zen-1983dc5f3292afa0b1b2b991428a91f111d34b8c.zip | |
Fixed some unreferenced variable warnings (why don't we get these in sln builds?). Also added size verification to certain payloads
Diffstat (limited to 'zenserver/compute/apply.cpp')
| -rw-r--r-- | zenserver/compute/apply.cpp | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/zenserver/compute/apply.cpp b/zenserver/compute/apply.cpp index 7b76bb80b..2c3243655 100644 --- a/zenserver/compute/apply.cpp +++ b/zenserver/compute/apply.cpp @@ -659,16 +659,21 @@ HttpFunctionService::ExecAction(const WorkerDesc& Worker, CbObject Action) { CbObjectView ExecEntry = It.AsObjectView(); - std::string_view Name = ExecEntry["name"sv].AsString(); - const IoHash Hash = ExecEntry["hash"sv].AsHash(); - const uint64_t Size = ExecEntry["size"sv].AsUInt64(); + std::string_view Name = ExecEntry["name"sv].AsString(); + const IoHash ChunkHash = ExecEntry["hash"sv].AsHash(); + const uint64_t Size = ExecEntry["size"sv].AsUInt64(); std::filesystem::path FilePath{SandboxPath / Name}; - IoBuffer DataBuffer = m_CasStore.FindChunk(Hash); + IoBuffer DataBuffer = m_CasStore.FindChunk(ChunkHash); if (!DataBuffer) { - throw std::runtime_error("worker CAS chunk '{}' missing"_format(Hash)); + throw std::runtime_error("worker CAS chunk '{}' missing"_format(ChunkHash)); + } + + if (DataBuffer.Size() != Size) + { + throw std::runtime_error("worker CAS chunk '{}' size: {}, action spec expected {}"_format(ChunkHash, DataBuffer.Size(), Size)); } zen::WriteFile(FilePath, DataBuffer); @@ -685,16 +690,21 @@ HttpFunctionService::ExecAction(const WorkerDesc& Worker, CbObject Action) { CbObjectView FileEntry = It.AsObjectView(); - std::string_view Name = FileEntry["name"sv].AsString(); - const IoHash Hash = FileEntry["hash"sv].AsHash(); - const uint64_t Size = FileEntry["size"sv].AsUInt64(); + std::string_view Name = FileEntry["name"sv].AsString(); + const IoHash ChunkHash = FileEntry["hash"sv].AsHash(); + const uint64_t Size = FileEntry["size"sv].AsUInt64(); std::filesystem::path FilePath{SandboxPath / Name}; - IoBuffer DataBuffer = m_CasStore.FindChunk(Hash); + IoBuffer DataBuffer = m_CasStore.FindChunk(ChunkHash); if (!DataBuffer) { - throw std::runtime_error("worker CAS chunk '{}' missing"_format(Hash)); + throw std::runtime_error("worker CAS chunk '{}' missing"_format(ChunkHash)); + } + + if (DataBuffer.Size() != Size) + { + throw std::runtime_error("worker CAS chunk '{}' size: {}, action spec expected {}"_format(ChunkHash, DataBuffer.Size(), Size)); } zen::WriteFile(FilePath, DataBuffer); |