From fff831616a3628fa46987ebdf9504708d900b93b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 16 Oct 2023 22:42:35 -0400 Subject: [PATCH] Fix ahnyQuab ogg decompression crashes. This issue was introduced when `hsStream::Close()` was removed in favor of RAII. Unfortunately, the patcher is handing off files before it deletes the patcher stream, which causes race conditions around zlib decompression not being complete. We need to explicitly close the underlying stream before performing any handoffs to prevent crashes. --- Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp b/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp index 3a7f887fdc..4da76ea590 100644 --- a/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp +++ b/Sources/Plasma/FeatureLib/pfPatcher/pfPatcher.cpp @@ -264,6 +264,13 @@ class pfPatcherStream : public plZlibStream return retVal; } + void Close() + { + if (hsCheckBits(fFlags, kFlagZipped)) + plZlibStream::Close(); + fOutput.reset(); + } + uint32_t Write(uint32_t count, const void* buf) override { // tick whatever progress bar we have @@ -383,6 +390,14 @@ static void IFileThingDownloadCB(ENetError result, void* param, const plFileName pfPatcherWorker* patcher = static_cast(param); pfPatcherStream* stream = static_cast(writer); + // We need to explicitly close any underlying streams NOW because we + // might be about to signal the client that this file needs to be acted + // on, eg installed, decompressed from ogg to wave, etc. We can't wait + // for hsStream's RAII to close the stream at the end of this function or + // the callback code may crash due to either a permissions error or the + // zlib decompression not being complete. + stream->Close(); + if (IS_NET_SUCCESS(result)) { PatcherLogGreen("\tDownloaded File '{}'", stream->GetFileName()); patcher->WhitelistFile(stream->GetFileName(), true);