Ignore invalid replay files instead of crashing.

This commit is contained in:
Paul Chote
2016-11-06 16:04:24 +00:00
parent 7ba0c22346
commit ab344b390d

View File

@@ -78,12 +78,10 @@ namespace OpenRA.FileFormats
} }
public static ReplayMetadata Read(string path) public static ReplayMetadata Read(string path)
{
try
{ {
using (var fs = new FileStream(path, FileMode.Open)) using (var fs = new FileStream(path, FileMode.Open))
return Read(fs, path);
}
static ReplayMetadata Read(FileStream fs, string path)
{ {
if (!fs.CanSeek) if (!fs.CanSeek)
return null; return null;
@@ -91,33 +89,17 @@ namespace OpenRA.FileFormats
if (fs.Length < 20) if (fs.Length < 20)
return null; return null;
try
{
fs.Seek(-(4 + 4), SeekOrigin.End); fs.Seek(-(4 + 4), SeekOrigin.End);
var dataLength = fs.ReadInt32(); var dataLength = fs.ReadInt32();
if (fs.ReadInt32() == MetaEndMarker) if (fs.ReadInt32() == MetaEndMarker)
{ {
// go back by (end marker + length storage + data + version + start marker) bytes // Go back by (end marker + length storage + data + version + start marker) bytes
fs.Seek(-(4 + 4 + dataLength + 4 + 4), SeekOrigin.Current); fs.Seek(-(4 + 4 + dataLength + 4 + 4), SeekOrigin.Current);
try
{
return new ReplayMetadata(fs, path); return new ReplayMetadata(fs, path);
} }
catch (YamlException ex)
{
Log.Write("debug", ex.ToString());
}
catch (InvalidOperationException ex)
{
Log.Write("debug", ex.ToString());
}
catch (NotSupportedException ex)
{
Log.Write("debug", ex.ToString());
} }
} }
} catch (Exception ex)
catch (IOException ex)
{ {
Log.Write("debug", ex.ToString()); Log.Write("debug", ex.ToString());
} }