From bb838c5b1f08230a2de4f5eed1b435cdfaa67dd8 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Tue, 3 Jan 2023 23:43:34 -0800 Subject: [PATCH] Fix error for small executables --- BurnOutSharp.Builders/PortableExecutable.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BurnOutSharp.Builders/PortableExecutable.cs b/BurnOutSharp.Builders/PortableExecutable.cs index 9ea5a430..bc2da23d 100644 --- a/BurnOutSharp.Builders/PortableExecutable.cs +++ b/BurnOutSharp.Builders/PortableExecutable.cs @@ -1299,8 +1299,8 @@ namespace BurnOutSharp.Builders // Get the section size int size = (int)sections.First(s => s.PointerToRawData == initialOffset).SizeOfRawData; - // Align to the 512-byte boundary or we find the start of an MS-DOS header - while (data.Position - initialOffset < size && data.Position % 0x200 != 0) + // Align to the 512-byte boundary, we find the start of an MS-DOS header, or the end of the file + while (data.Position - initialOffset < size && data.Position % 0x200 != 0 && data.Position < data.Length - 1) { // If we find the start of an MS-DOS header if (data.ReadUInt16() == Models.MSDOS.Constants.SignatureUInt16)