Don't crash when parsing corrupt sound files
Log the exception and move to the next parser.
This commit is contained in:
@@ -175,8 +175,22 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
channels = sampleBits = sampleRate = 0;
|
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;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
channels = 1;
|
channels = 1;
|
||||||
sampleBits = 16;
|
sampleBits = 16;
|
||||||
|
|||||||
@@ -190,8 +190,21 @@ namespace OpenRA.FileFormats
|
|||||||
rawData = null;
|
rawData = null;
|
||||||
channels = sampleBits = sampleRate = 0;
|
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;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
rawData = RawOutput;
|
rawData = RawOutput;
|
||||||
channels = Channels;
|
channels = Channels;
|
||||||
|
|||||||
Reference in New Issue
Block a user