From e5cbe71acc75e8ce0b7bb1ff264e5c826e218bc5 Mon Sep 17 00:00:00 2001 From: Denis <146707790+dnzbk@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:55:15 +0300 Subject: [PATCH] Fix: segmentation fault with HealthCheck=None and forced repair (#475) --- daemon/postprocess/ParChecker.cpp | 22 +++++++++++++++++----- daemon/postprocess/ParChecker.h | 2 +- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/daemon/postprocess/ParChecker.cpp b/daemon/postprocess/ParChecker.cpp index 63749fb7..929429ae 100644 --- a/daemon/postprocess/ParChecker.cpp +++ b/daemon/postprocess/ParChecker.cpp @@ -1040,9 +1040,13 @@ void ParChecker::SignalDone(std::string fileName, int available, int total) bool fileExists = true; for (Par2::Par2RepairerSourceFile* sourcefile : GetRepairer()->sourcefiles) { + if (!sourcefile) + { + continue; + } + std::string targetFileName = sourcefile->TargetFileName(); - if (sourcefile && !strcmp(fileName.c_str(), FileSystem::BaseFileName(targetFileName.c_str())) && - !sourcefile->GetTargetExists()) + if (!sourcefile->GetTargetExists() && fileName == FileSystem::BaseFileName(targetFileName.c_str())) { fileExists = false; break; @@ -1124,6 +1128,11 @@ void ParChecker::SaveSourceList() for (Par2::Par2RepairerSourceFile* sourcefile : GetRepairer()->sourcefiles) { + if (!sourcefile) + { + continue; + } + std::vector::iterator it2 = sourcefile->SourceBlocks(); for (int i = 0; i < (int)sourcefile->BlockCount(); i++, it2++) { @@ -1144,14 +1153,17 @@ void ParChecker::DeleteLeftovers() // corresponding target-files. If not - the source file was replaced. In this case // the DiskFile-object points to the renamed bak-file, which we can delete. - for (void* sf : m_sourceFiles) + for (Par2::DiskFile* sourceFile : m_sourceFiles) { - Par2::DiskFile* sourceFile = (Par2::DiskFile*)sf; + if (!sourceFile) + { + continue; + } bool found = false; for (Par2::Par2RepairerSourceFile* sourcefile : GetRepairer()->sourcefiles) { - if (sourcefile->GetTargetFile() == sourceFile) + if (sourcefile && sourcefile->GetTargetFile() == sourceFile) { found = true; break; diff --git a/daemon/postprocess/ParChecker.h b/daemon/postprocess/ParChecker.h index a37f3c87..63b930df 100644 --- a/daemon/postprocess/ParChecker.h +++ b/daemon/postprocess/ParChecker.h @@ -167,7 +167,7 @@ class ParChecker }; typedef std::deque FileList; - typedef std::deque SourceList; + typedef std::deque SourceList; typedef std::vector ValidBlocks; bool m_queuedParFilesChanged;