Found the real issue

This commit is contained in:
Matt Nadareski
2025-09-10 20:46:32 -04:00
parent 350d1c8d31
commit 2459d88951
2 changed files with 8 additions and 12 deletions

View File

@@ -192,6 +192,7 @@ namespace SabreTools.Serialization.Deserializers
Array.Resize(ref localEntries, localEntries.Length + 1);
pex.ResourceDirectoryTable.Entries = localEntries;
int length = (int)(tableSize - (data.Position - tableStart));
length = (int)Math.Min(length, data.Length - data.Position);
pex.ResourceDirectoryTable.Entries[localEntries.Length - 1] = new ResourceDirectoryEntry
{
@@ -357,8 +358,9 @@ namespace SabreTools.Serialization.Deserializers
/// Parse a Stream into an BaseRelocationBlock
/// </summary>
/// <param name="data">Stream to parse</param>
/// <param name="endOffset">First address not part of the base relocation table</param>
/// <returns>Filled BaseRelocationBlock on success, null on error</returns>
public static BaseRelocationBlock? ParseBaseRelocationBlock(Stream data)
public static BaseRelocationBlock? ParseBaseRelocationBlock(Stream data, long endOffset)
{
var obj = new BaseRelocationBlock();
@@ -370,6 +372,8 @@ namespace SabreTools.Serialization.Deserializers
// Guard against invalid block sizes
if (obj.BlockSize % 2 != 0)
return obj;
if (data.Position + obj.BlockSize > endOffset)
return obj;
int entryCount = ((int)obj.BlockSize - 8) / 2;
obj.TypeOffsetFieldEntries = new BaseRelocationTypeOffsetFieldEntry[entryCount];
@@ -396,7 +400,7 @@ namespace SabreTools.Serialization.Deserializers
while (data.Position < endOffset && data.Position < data.Length)
{
var block = ParseBaseRelocationBlock(data);
var block = ParseBaseRelocationBlock(data, endOffset);
if (block == null)
break;

View File

@@ -557,16 +557,8 @@ namespace SabreTools.Serialization.Printers
var typeOffsetFieldEntry = baseRelocationTableEntry.TypeOffsetFieldEntries[j];
builder.AppendLine($" Type and Offset Entry {j}");
if (typeOffsetFieldEntry == null)
{
builder.AppendLine($" Type: [NULL]");
builder.AppendLine($" Offset: [NULL]");
}
else
{
builder.AppendLine($" Type: {typeOffsetFieldEntry.BaseRelocationType} (0x{typeOffsetFieldEntry.BaseRelocationType:X})");
builder.AppendLine(typeOffsetFieldEntry.Offset, " Offset");
}
builder.AppendLine($" Type: {typeOffsetFieldEntry.BaseRelocationType} (0x{typeOffsetFieldEntry.BaseRelocationType:X})");
builder.AppendLine(typeOffsetFieldEntry.Offset, " Offset");
}
}