1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-24 15:24:30 +01:00

Fix #24904: gracefully handle incomplete CSS files (#24923)

* Fix #24904: gracefully handle incomplete CSS files

Some CSS files are truncated, possibly due to users overwriting RCT2
assets with parts of RCT1. This causes incorrect access to freed memory
and potential double frees.

This change verifies CSS data has expected samples and if not, informs
user about incorrect assets. The samples that exist are still loaded and
available for use.

There was no backtrace report generated for this on Windows.

* Skip reading of unused variables
This commit is contained in:
Michał Janiszewski
2025-08-09 23:56:12 +02:00
committed by GitHub
parent 0fee079931
commit c54466ec28
6 changed files with 89 additions and 46 deletions

View File

@@ -15,6 +15,9 @@
#include "../core/File.h"
#include "../core/Json.hpp"
#include "../core/Path.hpp"
#include "../localisation/Formatting.h"
#include "../localisation/StringIds.h"
#include "../ui/UiContext.h"
#include "Object.h"
using namespace OpenRCT2;
@@ -160,6 +163,17 @@ IAudioSource* AudioSampleTable::LoadSample(uint32_t index) const
auto& audioContext = GetContext()->GetAudioContext();
if (entry.PathIndex)
{
auto originalPosition = stream->GetPosition();
auto numSounds = stream->ReadValue<uint32_t>();
stream->SetPosition(originalPosition);
if (*entry.PathIndex >= numSounds)
{
auto& ui = GetContext()->GetUiContext();
ui.ShowMessageBox(FormatStringID(
STR_AUDIO_FILE_TRUNCATED, entry.Asset->GetPath().c_str(), *entry.PathIndex, numSounds));
}
result = audioContext.CreateStreamFromCSS(std::move(stream), *entry.PathIndex);
}
else