Fixes .hdr+.cab installshield cabinet files not being extracted by BOS when relative paths are provided. (#374)

* Fixes .hdr+.cab installshield cabinet files not being extracted when relative paths are provided.

* Fix for unit tests empty file string.

* Better fix for unit test failures, due to https://learn.microsoft.com/en-us/dotnet/api/system.io.path.getfullpath?view=net-9.0 listing several more exceptions than the other functions, most of which I would not imagine should be directly handled.

* Removed try-catch fullpath obtaining, added getting fullpath in scanner via filestream name instead.

* Undid previous changes again, re-added path assertion at request, added assert.throws exception for empty paths in the unit tests
This commit is contained in:
HeroponRikiBestest
2025-07-04 14:34:31 -04:00
committed by GitHub
parent c0c94fd78d
commit dff15ef799
3 changed files with 7 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using BinaryObjectScanner.FileType;
using Xunit;
@@ -25,8 +26,7 @@ namespace BinaryObjectScanner.Test.FileType
string outDir = string.Empty;
var extractable = new InstallShieldCAB();
bool actual = extractable.Extract(stream, file, outDir, includeDebug: false);
Assert.False(actual);
Assert.Throws<ArgumentException>(() => extractable.Extract(stream, file, outDir, includeDebug: false));
}
[Fact]
@@ -37,8 +37,7 @@ namespace BinaryObjectScanner.Test.FileType
string outDir = string.Empty;
var extractable = new InstallShieldCAB();
bool actual = extractable.Extract(stream, file, outDir, includeDebug: false);
Assert.False(actual);
Assert.Throws<ArgumentException>(() => extractable.Extract(stream, file, outDir, includeDebug: false));
}
}
}

View File

@@ -24,6 +24,8 @@ namespace BinaryObjectScanner.FileType
/// <inheritdoc/>
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
{
// Handles getting full path if relative paths were passed.
file = Path.GetFullPath(file);
// Get the name of the first cabinet file or header
var directory = Path.GetDirectoryName(file);
string noExtension = Path.GetFileNameWithoutExtension(file);

View File

@@ -207,7 +207,7 @@ namespace BinaryObjectScanner
try
{
using FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return GetInternalProtections(file, fs);
return GetInternalProtections(fs.Name, fs);
}
catch (Exception ex)
{