diff --git a/OpenRA.Game/FileFormats/AudLoader.cs b/OpenRA.Game/FileFormats/AudLoader.cs index 7896a754d0..d7f7bfc9f5 100644 --- a/OpenRA.Game/FileFormats/AudLoader.cs +++ b/OpenRA.Game/FileFormats/AudLoader.cs @@ -175,8 +175,22 @@ namespace OpenRA.FileFormats { channels = sampleBits = sampleRate = 0; - if (!LoadSound(stream, out rawData)) + try + { + if (!LoadSound(stream, out rawData)) + return false; + } + catch (Exception e) + { + // LoadSound() will check if the stream is in a format that this parser supports. + // If not, it will simply return false so we know we can't use it. If it is, it will start + // parsing the data without any further failsafes, which means that it will crash on corrupted files + // (that end prematurely or otherwise don't conform to the specifications despite the headers being OK). + Log.Write("debug", "Failed to parse AUD file {0}. Error message:".F(fileName)); + Log.Write("debug", e.ToString()); + rawData = null; return false; + } channels = 1; sampleBits = 16; diff --git a/OpenRA.Game/FileFormats/WavLoader.cs b/OpenRA.Game/FileFormats/WavLoader.cs index 6a3518fa5a..3f7d3fba2a 100644 --- a/OpenRA.Game/FileFormats/WavLoader.cs +++ b/OpenRA.Game/FileFormats/WavLoader.cs @@ -190,8 +190,21 @@ namespace OpenRA.FileFormats rawData = null; channels = sampleBits = sampleRate = 0; - if (!LoadSound(stream)) + try + { + if (!LoadSound(stream)) + return false; + } + catch (Exception e) + { + // LoadSound() will check if the stream is in a format that this parser supports. + // If not, it will simply return false so we know we can't use it. If it is, it will start + // parsing the data without any further failsafes, which means that it will crash on corrupted files + // (that end prematurely or otherwise don't conform to the specifications despite the headers being OK). + Log.Write("debug", "Failed to parse WAV file {0}. Error message:".F(fileName)); + Log.Write("debug", e.ToString()); return false; + } rawData = RawOutput; channels = Channels;