Stream safety and better streams

This commit is contained in:
Matt Nadareski
2022-12-15 14:20:27 -08:00
parent 16e71c910e
commit aded5ee03a
13 changed files with 98 additions and 33 deletions

View File

@@ -29,8 +29,7 @@ namespace BurnOutSharp.Builder
return null;
// Create a memory stream and parse that
MemoryStream dataStream = new MemoryStream(data);
dataStream.Position = offset;
MemoryStream dataStream = new MemoryStream(data, offset, data.Length - offset);
return ParseExecutable(dataStream);
}
@@ -46,7 +45,7 @@ namespace BurnOutSharp.Builder
public static Executable ParseExecutable(Stream data)
{
// If the data is invalid
if (data == null)
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
return null;
// If the offset is out of bounds