mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-09-22 14:55:11 +00:00
Protect against odd end-of-stream issues
This commit is contained in:
@@ -372,7 +372,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// TODO: Use marshalling here instead of building
|
||||
var residentNameTable = new List<ResidentNameTableEntry>();
|
||||
|
||||
while (data.Position < endOffset)
|
||||
while (data.Position < endOffset && data.Position < data.Length)
|
||||
{
|
||||
var entry = ParseResidentNameTableEntry(data);
|
||||
if (entry == null)
|
||||
@@ -445,7 +445,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// TODO: Use marshalling here instead of building
|
||||
var importedNameTable = new Dictionary<ushort, ImportedNameTableEntry>();
|
||||
|
||||
while (data.Position < endOffset)
|
||||
while (data.Position < endOffset && data.Position < data.Length)
|
||||
{
|
||||
ushort currentOffset = (ushort)data.Position;
|
||||
var entry = ParseImportedNameTableEntry(data);
|
||||
@@ -485,7 +485,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// TODO: Use marshalling here instead of building
|
||||
var entryTable = new List<EntryTableBundle>();
|
||||
|
||||
while (data.Position < endOffset)
|
||||
while (data.Position < endOffset && data.Position < data.Length)
|
||||
{
|
||||
var entry = new EntryTableBundle();
|
||||
entry.EntryCount = data.ReadByteValue();
|
||||
@@ -524,7 +524,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// TODO: Use marshalling here instead of building
|
||||
var residentNameTable = new List<NonResidentNameTableEntry>();
|
||||
|
||||
while (data.Position < endOffset)
|
||||
while (data.Position < endOffset && data.Position < data.Length)
|
||||
{
|
||||
var entry = ParseNonResidentNameTableEntry(data);
|
||||
if (entry == null)
|
||||
|
||||
@@ -703,7 +703,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
// TODO: Use marshalling here instead of building
|
||||
var baseRelocationTable = new List<BaseRelocationBlock>();
|
||||
|
||||
while (data.Position < endOffset)
|
||||
while (data.Position < endOffset && data.Position < data.Length)
|
||||
{
|
||||
var baseRelocationBlock = new BaseRelocationBlock();
|
||||
|
||||
@@ -724,12 +724,12 @@ namespace SabreTools.Serialization.Deserializers
|
||||
totalSize += 2;
|
||||
}
|
||||
|
||||
baseRelocationBlock.TypeOffsetFieldEntries = typeOffsetFieldEntries.ToArray();
|
||||
baseRelocationBlock.TypeOffsetFieldEntries = [.. typeOffsetFieldEntries];
|
||||
|
||||
baseRelocationTable.Add(baseRelocationBlock);
|
||||
}
|
||||
|
||||
return baseRelocationTable.ToArray();
|
||||
return [.. baseRelocationTable];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -745,7 +745,7 @@ namespace SabreTools.Serialization.Deserializers
|
||||
|
||||
var debugDirectoryTable = new List<DebugDirectoryEntry>();
|
||||
|
||||
while (data.Position < endOffset)
|
||||
while (data.Position < endOffset && data.Position < data.Length)
|
||||
{
|
||||
var debugDirectoryEntry = data.ReadType<DebugDirectoryEntry>();
|
||||
if (debugDirectoryEntry == null)
|
||||
|
||||
Reference in New Issue
Block a user