mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-17 06:14:59 +00:00
Stream safety and better streams
This commit is contained in:
@@ -233,8 +233,16 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <returns>An NE executable wrapper on success, null on failure</returns>
|
||||
public static NewExecutable Create(byte[] data, int offset)
|
||||
{
|
||||
MemoryStream dataStream = new MemoryStream(data);
|
||||
dataStream.Position = offset;
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
// If the offset is out of bounds
|
||||
if (offset < 0 || offset >= data.Length)
|
||||
return null;
|
||||
|
||||
// Create a memory stream and use that
|
||||
MemoryStream dataStream = new MemoryStream(data, offset, data.Length - offset);
|
||||
return Create(dataStream);
|
||||
}
|
||||
|
||||
@@ -245,6 +253,10 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <returns>An NE executable wrapper on success, null on failure</returns>
|
||||
public static NewExecutable Create(Stream data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null || data.Length == 0 || !data.CanSeek || !data.CanRead)
|
||||
return null;
|
||||
|
||||
var executable = Builder.NewExecutable.ParseExecutable(data);
|
||||
if (executable == null)
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user