Skip to content

Commit dff15ef

Browse files
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
1 parent c0c94fd commit dff15ef

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

BinaryObjectScanner.Test/FileType/InstallShieldCABTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.IO;
1+
using System;
2+
using System.IO;
23
using BinaryObjectScanner.FileType;
34
using Xunit;
45

@@ -25,8 +26,7 @@ public void ExtractStream_Null_False()
2526
string outDir = string.Empty;
2627
var extractable = new InstallShieldCAB();
2728

28-
bool actual = extractable.Extract(stream, file, outDir, includeDebug: false);
29-
Assert.False(actual);
29+
Assert.Throws<ArgumentException>(() => extractable.Extract(stream, file, outDir, includeDebug: false));
3030
}
3131

3232
[Fact]
@@ -37,8 +37,7 @@ public void ExtractStream_Empty_False()
3737
string outDir = string.Empty;
3838
var extractable = new InstallShieldCAB();
3939

40-
bool actual = extractable.Extract(stream, file, outDir, includeDebug: false);
41-
Assert.False(actual);
40+
Assert.Throws<ArgumentException>(() => extractable.Extract(stream, file, outDir, includeDebug: false));
4241
}
4342
}
4443
}

BinaryObjectScanner/FileType/InstallShieldCAB.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public bool Extract(string file, string outDir, bool includeDebug)
2424
/// <inheritdoc/>
2525
public bool Extract(Stream? stream, string file, string outDir, bool includeDebug)
2626
{
27+
// Handles getting full path if relative paths were passed.
28+
file = Path.GetFullPath(file);
2729
// Get the name of the first cabinet file or header
2830
var directory = Path.GetDirectoryName(file);
2931
string noExtension = Path.GetFileNameWithoutExtension(file);

BinaryObjectScanner/Scanner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ private ProtectionDictionary GetInternalProtections(string file)
207207
try
208208
{
209209
using FileStream fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
210-
return GetInternalProtections(file, fs);
210+
return GetInternalProtections(fs.Name, fs);
211211
}
212212
catch (Exception ex)
213213
{

0 commit comments

Comments
 (0)