Increase extraction safety

This commit is contained in:
Matt Nadareski
2024-12-03 03:43:39 -05:00
parent 6b7ad781b7
commit c70b5f6ec8
7 changed files with 23 additions and 4 deletions

View File

@@ -30,6 +30,9 @@ namespace BinaryObjectScanner.FileType
// Not supported for .NET Framework 2.0 or .NET Framework 3.5 due to library support
return false;
#else
if (stream == null || !stream.CanRead)
return false;
try
{
using var msi = new CompoundFile(stream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default);

View File

@@ -25,6 +25,9 @@ namespace BinaryObjectScanner.FileType
{
try
{
if (!File.Exists(file))
return false;
var archive = new ISv3(file);
foreach (var cfile in archive.Files)
{
@@ -39,10 +42,8 @@ namespace BinaryObjectScanner.FileType
if (fileContents == null || !string.IsNullOrEmpty(error))
continue;
using (FileStream fs = File.OpenWrite(tempFile))
{
fs.Write(fileContents, 0, fileContents.Length);
}
using FileStream fs = File.OpenWrite(tempFile);
fs.Write(fileContents, 0, fileContents.Length);
}
catch (Exception ex)
{

View File

@@ -54,6 +54,9 @@ namespace BinaryObjectScanner.FileType
try
{
if (!File.Exists(file))
return false;
var cabfile = InstallShieldCabinet.Open(file);
if (cabfile?.HeaderList == null)
return false;

View File

@@ -32,6 +32,9 @@ namespace BinaryObjectScanner.FileType
#else
try
{
if (!File.Exists(file))
return false;
// Try to open the archive and listfile
var mpqArchive = new MpqArchive(file, FileAccess.Read);
string? listfile = null;

View File

@@ -33,6 +33,9 @@ namespace BinaryObjectScanner.FileType
#else
try
{
if (!File.Exists(file))
return false;
// Loop over each entry
var cabArchive = new MSCabinet(file);
foreach (var compressedFile in cabArchive.GetFiles())

View File

@@ -24,6 +24,9 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
if (stream == null || !stream.CanRead)
return false;
try
{
var data = Decompressor.Decompress(stream);

View File

@@ -26,6 +26,9 @@ namespace BinaryObjectScanner.FileType
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
#if NET462_OR_GREATER || NETCOREAPP
if (stream == null || !stream.CanRead)
return false;
try
{
// Try opening the stream