Don't crash when parsing corrupt sound files

Log the exception and move to the next parser.
This commit is contained in:
Pavel Penev
2015-12-11 02:19:17 +02:00
parent 8542ed33ce
commit 42c98ec154
2 changed files with 29 additions and 2 deletions

View File

@@ -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;