From d9d84a01e56dbd03000270e2d9186bb2232e15a1 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 10 Feb 2022 10:37:57 -0800 Subject: [PATCH] Fix crash in SolidShield scanning (fixes #76) --- .../ExecutableType/Microsoft/PortableExecutable.cs | 11 ++++++++++- BurnOutSharp/ProtectionType/SolidShield.cs | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs b/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs index 82bbcbc1..715207c2 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs @@ -343,7 +343,16 @@ namespace BurnOutSharp.ExecutableType.Microsoft int startingIndex = (int)Math.Max(section.PointerToRawData + offset, 0); int readLength = (int)Math.Min(section.VirtualSize - offset, content.Length); - return content.ReadBytes(ref startingIndex, readLength); + try + { + return content.ReadBytes(ref startingIndex, readLength); + } + catch + { + // Just absorb errors for now + // TODO: Investigate why and when this would be hit + return null; + } } #endregion diff --git a/BurnOutSharp/ProtectionType/SolidShield.cs b/BurnOutSharp/ProtectionType/SolidShield.cs index 6310ac2e..171789ec 100644 --- a/BurnOutSharp/ProtectionType/SolidShield.cs +++ b/BurnOutSharp/ProtectionType/SolidShield.cs @@ -75,7 +75,7 @@ namespace BurnOutSharp.ProtectionType // Search the last two available sections var sectionNames = pex.GetSectionNames(); - for (int i = sectionNames.Length - 2; i < sectionNames.Length; i++) + for (int i = (sectionNames.Length >= 2 ? sectionNames.Length - 2 : 0); i < sectionNames.Length; i++) { var nthSectionRaw = pex.ReadRawSection(fileContent, sectionNames[i], first: false); if (nthSectionRaw != null)