diff --git a/BinaryObjectScanner/FileType/RAR.cs b/BinaryObjectScanner/FileType/RAR.cs index f1c7e1f9..4e0983b9 100644 --- a/BinaryObjectScanner/FileType/RAR.cs +++ b/BinaryObjectScanner/FileType/RAR.cs @@ -50,7 +50,14 @@ public class RAR : IExtractable if (entry.Key == null) continue; + // If we have a partial entry due to an incomplete multi-part archive, skip it + if (!entry.IsComplete) + continue; + string tempFile = Path.Combine(tempPath, entry.Key); + var directoryName = Path.GetDirectoryName(tempFile); + if (directoryName != null && !Directory.Exists(directoryName)) + Directory.CreateDirectory(directoryName); entry.WriteToFile(tempFile); } catch (Exception ex) diff --git a/BinaryObjectScanner/FileType/SevenZip.cs b/BinaryObjectScanner/FileType/SevenZip.cs index 4f384f6c..1c8927ef 100644 --- a/BinaryObjectScanner/FileType/SevenZip.cs +++ b/BinaryObjectScanner/FileType/SevenZip.cs @@ -50,7 +50,14 @@ public class SevenZip : IExtractable if (entry.Key == null) continue; + // If we have a partial entry due to an incomplete multi-part archive, skip it + if (!entry.IsComplete) + continue; + string tempFile = Path.Combine(tempPath, entry.Key); + var directoryName = Path.GetDirectoryName(tempFile); + if (directoryName != null && !Directory.Exists(directoryName)) + Directory.CreateDirectory(directoryName); entry.WriteToFile(tempFile); } catch (Exception ex) diff --git a/BinaryObjectScanner/FileType/TapeArchive.cs b/BinaryObjectScanner/FileType/TapeArchive.cs index 1711fdb2..c0c4f21a 100644 --- a/BinaryObjectScanner/FileType/TapeArchive.cs +++ b/BinaryObjectScanner/FileType/TapeArchive.cs @@ -50,7 +50,15 @@ public class TapeArchive : IExtractable if (entry.Key == null) continue; + // If we have a partial entry due to an incomplete multi-part archive, skip it + if (!entry.IsComplete) + continue; + + // TODO: Fix bug with extracting folders from tar. string tempFile = Path.Combine(tempPath, entry.Key); + var directoryName = Path.GetDirectoryName(tempFile); + if (directoryName != null && !Directory.Exists(directoryName)) + Directory.CreateDirectory(directoryName); entry.WriteToFile(tempFile); } catch (Exception ex) diff --git a/BinaryObjectScanner/Packer/WinRARSFX.cs b/BinaryObjectScanner/Packer/WinRARSFX.cs index 30252875..21ded408 100644 --- a/BinaryObjectScanner/Packer/WinRARSFX.cs +++ b/BinaryObjectScanner/Packer/WinRARSFX.cs @@ -39,15 +39,15 @@ public class WinRARSFX : IExtractablePortableExecutable, IPortableExecutableChec try { // Should be using stream instead of file, but stream fails to extract anything. My guess is that the executable portion of the archive is causing stream to fail, but not file. - using (RarArchive zipFile = RarArchive.Open(file, new ReaderOptions() { LookForHeader = true })) + using (RarArchive rarFile = RarArchive.Open(file, new ReaderOptions() { LookForHeader = true })) { - if (!zipFile.IsComplete) + if (!rarFile.IsComplete) return null; string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(tempPath); - foreach (var entry in zipFile.Entries) + foreach (var entry in rarFile.Entries) { try { @@ -59,7 +59,14 @@ public class WinRARSFX : IExtractablePortableExecutable, IPortableExecutableChec if (entry.Key == null) continue; + // If we have a partial entry due to an incomplete multi-part archive, skip it + if (!entry.IsComplete) + continue; + string tempFile = Path.Combine(tempPath, entry.Key); + var directoryName = Path.GetDirectoryName(tempFile); + if (directoryName != null && !Directory.Exists(directoryName)) + Directory.CreateDirectory(directoryName); entry.WriteToFile(tempFile); } catch (Exception ex)