aboutsummaryrefslogtreecommitdiff
path: root/zenstore/compactcas.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-04-01 09:07:25 +0200
committerDan Engelbrecht <[email protected]>2022-04-01 09:07:25 +0200
commit408127ffe2e02985fa20d972620383979a46848d (patch)
tree3bff601bc3cff78f2bab3971ba1390db574064cd /zenstore/compactcas.cpp
parentreserve space for log entries before replay (diff)
downloadzen-408127ffe2e02985fa20d972620383979a46848d.tar.xz
zen-408127ffe2e02985fa20d972620383979a46848d.zip
move chunk location validation to ValidateLegacyEntry
Diffstat (limited to 'zenstore/compactcas.cpp')
-rw-r--r--zenstore/compactcas.cpp26
1 files changed, 16 insertions, 10 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index 1ade002d8..51060ca94 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -210,7 +210,7 @@ namespace {
return Entries;
}
- bool ValidateLegacyEntry(const LegacyCasDiskIndexEntry& Entry, std::string& OutReason)
+ bool ValidateLegacyEntry(const LegacyCasDiskIndexEntry& Entry, uint64_t BlockFileSize, std::string& OutReason)
{
if (Entry.Key == IoHash::Zero)
{
@@ -234,6 +234,17 @@ 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;
}
@@ -368,14 +379,9 @@ namespace {
LegacyDiskIndex.erase(Record.Key);
return;
}
- if (!ValidateLegacyEntry(Record, InvalidEntryReason))
- {
- ZEN_WARN("skipping invalid entry in '{}', '{}'", LegacyLogPath, InvalidEntryReason);
- return;
- }
- uint64_t EntryEnd = Record.Location.GetOffset() + Record.Location.GetSize();
- if (EntryEnd > FileSize)
+ if (!ValidateLegacyEntry(Record, FileSize, InvalidEntryReason))
{
+ ZEN_WARN("skipping invalid entry in '{}', reason '{}'", LegacyLogPath, InvalidEntryReason);
return;
}
if (ExistingChunks.contains(Record.Key))
@@ -1479,7 +1485,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
{
if (!ValidateEntry(Entry, InvalidEntryReason))
{
- ZEN_WARN("skipping invalid entry in '{}', '{}'",
+ ZEN_WARN("skipping invalid entry in '{}', reason '{}'",
GetIndexPath(m_Config.RootDirectory, m_ContainerBaseName),
InvalidEntryReason);
continue;
@@ -1501,7 +1507,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
}
if (!ValidateEntry(Entry, InvalidEntryReason))
{
- ZEN_WARN("skipping invalid entry in '{}', '{}'",
+ ZEN_WARN("skipping invalid entry in '{}', reason '{}'",
GetLogPath(m_Config.RootDirectory, m_ContainerBaseName),
InvalidEntryReason);
continue;