From f092a4d2ea1509a9cfc0843d41487cfcc3183e6f Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 2 Dec 2024 14:43:40 -0500 Subject: [PATCH] CanSeek can throw exceptions --- BinaryObjectScanner/FileType/Executable.cs | 8 ++++---- BinaryObjectScanner/Scanner.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/BinaryObjectScanner/FileType/Executable.cs b/BinaryObjectScanner/FileType/Executable.cs index c1bc3a4b..e01e910d 100644 --- a/BinaryObjectScanner/FileType/Executable.cs +++ b/BinaryObjectScanner/FileType/Executable.cs @@ -165,14 +165,14 @@ namespace BinaryObjectScanner.FileType else if (!File.Exists(file)) return protections; - // If the stream isn't seekable - if (!stream.CanSeek) - return protections; - // Read the file contents byte[] fileContent = []; try { + // If the stream isn't seekable + if (!stream.CanSeek) + return protections; + stream.Seek(0, SeekOrigin.Begin); fileContent = stream.ReadBytes((int)stream.Length); if (fileContent == null) diff --git a/BinaryObjectScanner/Scanner.cs b/BinaryObjectScanner/Scanner.cs index bed0d840..c9b6c2b5 100644 --- a/BinaryObjectScanner/Scanner.cs +++ b/BinaryObjectScanner/Scanner.cs @@ -231,7 +231,7 @@ namespace BinaryObjectScanner private ProtectionDictionary GetInternalProtections(string fileName, Stream stream) { // Quick sanity check before continuing - if (stream == null || !stream.CanRead || !stream.CanSeek) + if (!stream.CanRead) return []; // Initialize the protections found