mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Found the real issue
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user