Add header length safeguards to PortableExecutable wrapper (#9)

This commit is contained in:
TheRogueArchivist
2024-06-05 20:19:35 -06:00
committed by GitHub
parent 73ec66e627
commit 1b412c3027

View File

@@ -45,7 +45,12 @@ namespace SabreTools.Serialization.Wrappers
.OrderBy(s => s)
.First();
int headerLength = (int)(firstSectionAddress - headerStartAddress);
_headerPaddingData = ReadFromDataSource((int)headerStartAddress, headerLength);
// Check if the header length is more than 0 before reading data
if (headerLength <= 0)
_headerPaddingData = [];
else
_headerPaddingData = ReadFromDataSource((int)headerStartAddress, headerLength);
// Cache and return the header padding data, even if null
return _headerPaddingData;
@@ -80,7 +85,12 @@ namespace SabreTools.Serialization.Wrappers
.OrderBy(s => s)
.First();
int headerLength = (int)(firstSectionAddress - headerStartAddress);
_headerPaddingStrings = ReadStringsFromDataSource((int)headerStartAddress, headerLength, charLimit: 3);
// Check if the header length is more than 0 before reading strings
if (headerLength <= 0)
_headerPaddingStrings = [];
else
_headerPaddingStrings = ReadStringsFromDataSource((int)headerStartAddress, headerLength, charLimit: 3);
// Cache and return the header padding data, even if null
return _headerPaddingStrings;