Verify mod hash after downloading

This commit is contained in:
Tixx 2025-05-01 20:42:01 +02:00
parent e216b6ec06
commit 25a1061700
No known key found for this signature in database
GPG Key ID: EC6E7A2BAABF0B8C

View File

@ -571,11 +571,16 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
OutFile.write(DownloadedFile.data(), DownloadedFile.size()); OutFile.write(DownloadedFile.data(), DownloadedFile.size());
OutFile.flush(); OutFile.flush();
} }
// 2. verify size // 2. verify size and hash
if (std::filesystem::file_size(PathToSaveTo) != DownloadedFile.size()) { if (std::filesystem::file_size(PathToSaveTo) != DownloadedFile.size()) {
error("Failed to write the entire file '" + PathToSaveTo + "' correctly (file size mismatch)"); error("Failed to write the entire file '" + PathToSaveTo + "' correctly (file size mismatch)");
Terminate = true; Terminate = true;
} }
if (GetSha256HashReallyFast(PathToSaveTo) != ModInfoIter->Hash) {
error("Failed to write or download the entire file '" + PathToSaveTo + "' correctly (hash mismatch)");
Terminate = true;
}
} while (fs::file_size(PathToSaveTo) != ModInfoIter->FileSize && !Terminate); } while (fs::file_size(PathToSaveTo) != ModInfoIter->FileSize && !Terminate);
if (!Terminate) { if (!Terminate) {
if (!fs::exists(GetGamePath() + "mods/multiplayer")) { if (!fs::exists(GetGamePath() + "mods/multiplayer")) {