diff options
| author | Dan Engelbrecht <[email protected]> | 2024-11-28 22:15:22 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-11-28 22:15:22 +0100 |
| commit | b2042256171a2973c9d39f33fd82934ed56ef29b (patch) | |
| tree | 3e1fa0a349086c694facc85ceb9115abbca32fce /src | |
| parent | Dashboard CSS fixes and archival of a partial treemap view (#242) (diff) | |
| download | zen-b2042256171a2973c9d39f33fd82934ed56ef29b.tar.xz zen-b2042256171a2973c9d39f33fd82934ed56ef29b.zip | |
fix oplog index path reading error (#246)
* when reading paths for oplog index, make sure we don't point our string view to potentially stale memory
Diffstat (limited to 'src')
| -rw-r--r-- | src/zenserver/projectstore/projectstore.cpp | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/src/zenserver/projectstore/projectstore.cpp b/src/zenserver/projectstore/projectstore.cpp index 6f669f68e..89fbff06c 100644 --- a/src/zenserver/projectstore/projectstore.cpp +++ b/src/zenserver/projectstore/projectstore.cpp @@ -1776,7 +1776,7 @@ ProjectStore::Oplog::ReadIndexSnapshot() Offset = RoundUp(Offset, OplogIndexHeader::DataAlignment); BasicFileBuffer IndexFile(ObjectIndexFile, 65536); - auto ReadString([&IndexFile, &Offset](uint32_t Length) -> std::string_view { + auto ReadString([&IndexFile, &Offset](uint32_t Length) -> std::string { MemoryView StringData = IndexFile.MakeView(Length, Offset); if (StringData.GetSize() != Length) { @@ -1785,15 +1785,15 @@ ProjectStore::Oplog::ReadIndexSnapshot() uint32_t(StringData.GetSize()))); } Offset += Length; - return std::string_view((const char*)StringData.GetData(), Length); + return std::string((const char*)StringData.GetData(), Length); }); for (uint64_t FileLengthOffset = 0; FileLengthOffset < FilePathLengths.size();) { - std::string_view ServerPath = ReadString(FilePathLengths[FileLengthOffset++]); - std::string_view ClientPath = ReadString(FilePathLengths[FileLengthOffset++]); + std::string ServerPath = ReadString(FilePathLengths[FileLengthOffset++]); + std::string ClientPath = ReadString(FilePathLengths[FileLengthOffset++]); m_FileMap.insert_or_assign( Keys[KeyOffset++], - FileMapEntry{.ServerPath = std::string(ServerPath), .ClientPath = std::string(ClientPath)}); + FileMapEntry{.ServerPath = std::move(ServerPath), .ClientPath = std::move(ClientPath)}); } } m_LogFlushPosition = Header.LogPosition; @@ -1978,32 +1978,38 @@ ProjectStore::Oplog::IterateChunks(std::span<Oid> ChunkIds, break; } WorkLatch.AddCount(1); - OptionalWorkerPool->ScheduleWork([this, &WorkLatch, ChunkIndex, &FileChunkIndexes, &FileChunkPaths, &AsyncCallback, &Result]() { - auto _ = MakeGuard([&WorkLatch]() { WorkLatch.CountDown(); }); - if (Result.load() == false) - { - return; - } - size_t FileChunkIndex = FileChunkIndexes[ChunkIndex]; - const std::filesystem::path& FilePath = FileChunkPaths[ChunkIndex]; - try - { - IoBuffer Payload = IoBufferBuilder::MakeFromFile(FilePath); - if (!AsyncCallback(FileChunkIndex, Payload)) + OptionalWorkerPool->ScheduleWork( + [this, &WorkLatch, &ChunkIds, ChunkIndex, &FileChunkIndexes, &FileChunkPaths, &AsyncCallback, &Result]() { + auto _ = MakeGuard([&WorkLatch]() { WorkLatch.CountDown(); }); + if (Result.load() == false) { - Result.store(false); + return; } - } - catch (const std::exception& Ex) - { - ZEN_WARN("oplog '{}/{}': exception caught when iterating file chunk {}, path '{}'. Reason: '{}'", - m_OuterProject->Identifier, - m_OplogId, - FileChunkIndex, - FilePath, - Ex.what()); - } - }); + size_t FileChunkIndex = FileChunkIndexes[ChunkIndex]; + const std::filesystem::path& FilePath = FileChunkPaths[ChunkIndex]; + try + { + IoBuffer Payload = IoBufferBuilder::MakeFromFile(FilePath); + if (!Payload) + { + ZEN_WARN("Trying to fetch chunk {} using file path {} failed", ChunkIds[ChunkIndex], FilePath); + } + + if (!AsyncCallback(FileChunkIndex, Payload)) + { + Result.store(false); + } + } + catch (const std::exception& Ex) + { + ZEN_WARN("oplog '{}/{}': exception caught when iterating file chunk {}, path '{}'. Reason: '{}'", + m_OuterProject->Identifier, + m_OplogId, + FileChunkIndex, + FilePath, + Ex.what()); + } + }); } WorkLatch.CountDown(); @@ -2054,7 +2060,12 @@ ProjectStore::Oplog::FindChunk(const Oid& ChunkId) OplogLock.ReleaseNow(); - return IoBufferBuilder::MakeFromFile(FilePath); + IoBuffer Result = IoBufferBuilder::MakeFromFile(FilePath); + if (!Result) + { + ZEN_WARN("Trying to fetch chunk {} using file path {} failed", ChunkId, FilePath); + } + return Result; } if (auto MetaIt = m_MetaMap.find(ChunkId); MetaIt != m_MetaMap.end()) |