diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-01 12:12:24 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-04-01 12:12:24 +0200 |
| commit | cdee054241c63a6427365ed34090e9812d963482 (patch) | |
| tree | 72545febd3f013036d5db03ec0c956e813029f1a /zenstore/compactcas.cpp | |
| parent | cleanup (diff) | |
| download | zen-cdee054241c63a6427365ed34090e9812d963482.tar.xz zen-cdee054241c63a6427365ed34090e9812d963482.zip | |
fix entry validation
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 51 |
1 files changed, 27 insertions, 24 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 3569b034b..2a4f3c012 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -210,22 +210,26 @@ namespace { return Entries; } - bool ValidateLegacyEntry(const LegacyCasDiskIndexEntry& Entry, uint64_t BlockFileSize, std::string& OutReason) + bool ValidateLegacyEntry(const LegacyCasDiskIndexEntry& Entry, std::string& OutReason) { if (Entry.Key == IoHash::Zero) { OutReason = fmt::format("Invalid hash key {}", Entry.Key.ToHexString()); return false; } - if (Entry.ContentType != ZenContentType::kUnknownContentType) + if ((Entry.Flags & ~LegacyCasDiskIndexEntry::kTombstone) != 0) { - OutReason = - fmt::format("Invalid content type {} for entry {}", static_cast<uint8_t>(Entry.ContentType), Entry.Key.ToHexString()); + OutReason = fmt::format("Invalid flags {} for entry {}", Entry.Flags, Entry.Key.ToHexString()); return false; } - if ((Entry.Flags & ~LegacyCasDiskIndexEntry::kTombstone) != 0) + if (Entry.Flags & LegacyCasDiskIndexEntry::kTombstone) { - OutReason = fmt::format("Invalid flags {} for entry {}", Entry.Flags, Entry.Key.ToHexString()); + return true; + } + if (Entry.ContentType != ZenContentType::kUnknownContentType) + { + OutReason = + fmt::format("Invalid content type {} for entry {}", static_cast<uint8_t>(Entry.ContentType), Entry.Key.ToHexString()); return false; } uint64_t Size = Entry.Location.GetSize(); @@ -234,17 +238,6 @@ namespace { OutReason = fmt::format("Invalid size {} for entry {}", Size, Entry.Key.ToHexString()); return false; } - uint64_t EntryStart = Entry.Location.GetOffset(); - uint64_t EntryEnd = EntryStart + Size; - if (EntryEnd > BlockFileSize) - { - OutReason = fmt::format("Invalid range {}:{}, outside of file size {} for entry {}", - EntryStart, - EntryEnd, - BlockFileSize, - Entry.Key.ToHexString()); - return false; - } return true; } @@ -255,15 +248,19 @@ namespace { OutReason = fmt::format("Invalid hash key {}", Entry.Key.ToHexString()); return false; } - if (Entry.ContentType != ZenContentType::kUnknownContentType) + if ((Entry.Flags & ~CasDiskIndexEntry::kTombstone) != 0) { - OutReason = - fmt::format("Invalid content type {} for entry {}", static_cast<uint8_t>(Entry.ContentType), Entry.Key.ToHexString()); + OutReason = fmt::format("Invalid flags {} for entry {}", Entry.Flags, Entry.Key.ToHexString()); return false; } - if ((Entry.Flags & ~CasDiskIndexEntry::kTombstone) != 0) + if (Entry.Flags & CasDiskIndexEntry::kTombstone) { - OutReason = fmt::format("Invalid flags {} for entry {}", Entry.Flags, Entry.Key.ToHexString()); + return true; + } + if (Entry.ContentType != ZenContentType::kUnknownContentType) + { + OutReason = + fmt::format("Invalid content type {} for entry {}", static_cast<uint8_t>(Entry.ContentType), Entry.Key.ToHexString()); return false; } uint64_t Size = Entry.Location.GetSize(); @@ -379,7 +376,7 @@ namespace { LegacyDiskIndex.erase(Record.Key); return; } - if (!ValidateLegacyEntry(Record, FileSize, InvalidEntryReason)) + if (!ValidateLegacyEntry(Record, InvalidEntryReason)) { ZEN_WARN("skipping invalid entry in '{}', reason '{}'", LegacyLogPath, InvalidEntryReason); return; @@ -1479,6 +1476,8 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) std::filesystem::path BasePath = GetBasePath(m_Config.RootDirectory, m_ContainerBaseName); std::filesystem::path LegacyLogPath = GetLegacyLogPath(m_Config.RootDirectory, m_ContainerBaseName); + bool MakeSnapshot = IsNewStore; + if (IsNewStore) { std::filesystem::path LegacySobsPath = GetLegacyUcasPath(m_Config.RootDirectory, m_ContainerBaseName); @@ -1503,7 +1502,6 @@ CasContainerStrategy::OpenContainer(bool IsNewStore) } } - bool MakeSnapshot = false; { std::vector<CasDiskIndexEntry> LogEntries = ReadLog(m_Config.RootDirectory, m_ContainerBaseName); std::string InvalidEntryReason; @@ -2343,6 +2341,11 @@ TEST_CASE("compactcas.legacyconversion") TCasLogFile<LegacyCasDiskIndexEntry> LegacyCasLog; std::filesystem::path SLegacylogPath = GetLegacyLogPath(CasConfig.RootDirectory, "test"); LegacyCasLog.Open(SLegacylogPath, CasLogFile::EMode::kTruncate); + + BasicFile UCasFile; + UCasFile.Open(LegacyCasPath, BasicFile::EMode::kRead); + uint64_t FileSize = UCasFile.FileSize(); + for (const CasDiskIndexEntry& Entry : LogEntries) { BlockStoreLocation Location = Entry.Location.Get(16); |