From 6ab7a06dd55075415ee5bd828e440f0d270e4714 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 11 Sep 2021 16:54:00 -0700 Subject: [PATCH] Lock stream when reading raw section --- .../ExecutableType/Microsoft/PortableExecutable.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs b/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs index 58efb340..f41efd4f 100644 --- a/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs +++ b/BurnOutSharp/ExecutableType/Microsoft/PortableExecutable.cs @@ -224,8 +224,15 @@ namespace BurnOutSharp.ExecutableType.Microsoft if (section == null) return null; - stream.Seek((int)section.PointerToRawData, SeekOrigin.Begin); - return stream.ReadBytes((int)section.VirtualSize); + lock (stream) + { + long originalPosition = stream.Position; + stream.Seek((int)section.PointerToRawData, SeekOrigin.Begin); + byte[] sectionData = stream.ReadBytes((int)section.VirtualSize); + stream.Seek(originalPosition, SeekOrigin.Begin); + return sectionData; + } + } ///