Limit overlay caching to int.MaxValue

This commit is contained in:
Matt Nadareski
2025-09-25 13:40:29 -04:00
parent 9574232719
commit c9794691bb
2 changed files with 6 additions and 0 deletions

View File

@@ -109,6 +109,7 @@ namespace SabreTools.Serialization.Wrappers
/// <summary>
/// Overlay data, if it exists
/// </summary>
/// <remarks>Can only cache up to <see cref="int.MaxValue"/> bytes</remarks>
/// <see href="https://codeberg.org/CYBERDEV/REWise/src/branch/master/src/exefile.c"/>
public byte[] OverlayData
{
@@ -154,6 +155,8 @@ namespace SabreTools.Serialization.Wrappers
// Otherwise, cache and return the data
long overlayLength = dataLength - endOfSectionData;
overlayLength = Math.Min(overlayLength, int.MaxValue);
_overlayData = ReadRangeFromSource((int)endOfSectionData, (int)overlayLength);
return _overlayData;
}

View File

@@ -362,6 +362,7 @@ namespace SabreTools.Serialization.Wrappers
/// <summary>
/// Overlay data, if it exists
/// </summary>
/// <remarks>Can only cache up to <see cref="int.MaxValue"/> bytes</remarks>
/// <see href="https://www.autoitscript.com/forum/topic/153277-pe-file-overlay-extraction/"/>
public byte[] OverlayData
{
@@ -407,6 +408,8 @@ namespace SabreTools.Serialization.Wrappers
// Otherwise, cache and return the data
long overlayLength = dataLength - endOfSectionData;
overlayLength = Math.Min(overlayLength, int.MaxValue);
_overlayData = ReadRangeFromSource(endOfSectionData, (int)overlayLength) ?? [];
return _overlayData;
}