Add more guards to PE builder

This commit is contained in:
Matt Nadareski
2022-12-10 14:21:37 -08:00
parent 92c5745ac8
commit 3c3fd1be50

View File

@@ -699,7 +699,7 @@ namespace BurnOutSharp.Builder
var strings = new List<string>();
uint totalSize = coffStringTable.TotalSize;
while (totalSize > 0)
while (totalSize > 0 && offset < data.Length)
{
int initialPosition = offset;
string str = data.ReadString(ref offset);
@@ -790,7 +790,7 @@ namespace BurnOutSharp.Builder
var typeOffsetFieldEntries = new List<BaseRelocationTypeOffsetFieldEntry>();
int totalSize = 8;
while (totalSize < baseRelocationBlock.BlockSize)
while (totalSize < baseRelocationBlock.BlockSize && offset < data.Length)
{
var baseRelocationTypeOffsetFieldEntry = new BaseRelocationTypeOffsetFieldEntry();
@@ -2024,7 +2024,7 @@ namespace BurnOutSharp.Builder
var typeOffsetFieldEntries = new List<BaseRelocationTypeOffsetFieldEntry>();
int totalSize = 8;
while (totalSize < baseRelocationBlock.BlockSize)
while (totalSize < baseRelocationBlock.BlockSize && data.Position < data.Length)
{
var baseRelocationTypeOffsetFieldEntry = new BaseRelocationTypeOffsetFieldEntry();