diff options
| author | Dan Engelbrecht <[email protected]> | 2025-09-04 13:17:25 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-09-04 13:17:25 +0200 |
| commit | 9f575bd416e1f7afbd11d4b221074f34bb89605c (patch) | |
| tree | 07c87ccdbc01cdaf13015f46dddfaa71fa791d5b /src/zenstore/buildstore/buildstore.cpp | |
| parent | oplog memory usage reduction (#482) (diff) | |
| download | zen-9f575bd416e1f7afbd11d4b221074f34bb89605c.tar.xz zen-9f575bd416e1f7afbd11d4b221074f34bb89605c.zip | |
add validation of compact binary payloads before reading them (#483)
* add validation of compact binary payloads before reading them
Diffstat (limited to 'src/zenstore/buildstore/buildstore.cpp')
| -rw-r--r-- | src/zenstore/buildstore/buildstore.cpp | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/src/zenstore/buildstore/buildstore.cpp b/src/zenstore/buildstore/buildstore.cpp index 1b2cf036b..d65c2bf06 100644 --- a/src/zenstore/buildstore/buildstore.cpp +++ b/src/zenstore/buildstore/buildstore.cpp @@ -3,6 +3,7 @@ #include <zenstore/buildstore/buildstore.h> #include <zencore/compactbinarybuilder.h> +#include <zencore/compactbinaryutil.h> #include <zencore/compress.h> #include <zencore/fmtutils.h> #include <zencore/logging.h> @@ -138,24 +139,33 @@ BuildStore::BuildStore(const BuildStoreConfig& Config, GcManager& Gc, CidStore& { RwLock::ExclusiveLockScope Lock(m_Lock); - CbObject ManifestReader = LoadCompactBinaryObject(ReadFile(ManifestPath).Flatten()); - Oid ManifestId = ManifestReader["id"].AsObjectId(); - uint32_t Version = ManifestReader["version"].AsUInt32(); - DateTime CreationDate = ManifestReader["createdAt"].AsDateTime(); - ZEN_UNUSED(CreationDate); - if (ManifestId == Oid::Zero || Version != blobstore::impl::ManifestVersion) + CbValidateError ValidateResult = CbValidateError::None; + if (CbObject ManifestReader = ValidateAndReadCompactBinaryObject(ReadFile(ManifestPath).Flatten(), ValidateResult); + ValidateResult == CbValidateError::None && ManifestReader) { - ZEN_WARN("Invalid manifest at {}, wiping state", ManifestPath); - IsNew = true; + Oid ManifestId = ManifestReader["id"].AsObjectId(); + uint32_t Version = ManifestReader["version"].AsUInt32(); + DateTime CreationDate = ManifestReader["createdAt"].AsDateTime(); + ZEN_UNUSED(CreationDate); + if (ManifestId == Oid::Zero || Version != blobstore::impl::ManifestVersion) + { + ZEN_WARN("Invalid manifest at {}, wiping state", ManifestPath); + IsNew = true; + } + else + { + m_BlobLogFlushPosition = ReadPayloadLog(Lock, BlobLogPath, 0); + m_MetaLogFlushPosition = ReadMetadataLog(Lock, MetaLogPath, 0); + if (IsFile(AccessTimesPath)) + { + ReadAccessTimes(Lock, AccessTimesPath); + } + } } else { - m_BlobLogFlushPosition = ReadPayloadLog(Lock, BlobLogPath, 0); - m_MetaLogFlushPosition = ReadMetadataLog(Lock, MetaLogPath, 0); - if (IsFile(AccessTimesPath)) - { - ReadAccessTimes(Lock, AccessTimesPath); - } + ZEN_WARN("Invalid manifest at {} ('{}'), wiping state", ManifestPath, ToString(ValidateResult)); + IsNew = true; } } |