From a06825bd813939e4b126173284c10fd145f7fe95 Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Mon, 1 Dec 2025 11:20:29 -0500 Subject: [PATCH 1/4] Explicitly handle password-protected archives rather than repeatedly throwing exceptions --- .../Wrappers/PKZIP.Extraction.cs | 12 ++++++++++ .../Wrappers/RAR.Extraction.cs | 24 +++++++++++++++++-- .../Wrappers/SevenZip.Extraction.cs | 24 +++++++++++++++++-- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs index 0d6ab1d3..45259e74 100644 --- a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs @@ -43,6 +43,7 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu zipFile = ZipArchive.Open(parts, readerOptions); } + bool encrypted = false; foreach (var entry in zipFile.Entries) { try @@ -58,6 +59,17 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu // If the entry is partial due to an incomplete multi-part archive, skip it if (!entry.IsComplete) continue; + + // If the entry is password-protected, skip it + if (entry.IsEncrypted) + { + if (!encrypted) + { + if (includeDebug) Console.WriteLine("Some or all files in zip are password-protected!"); + encrypted = true; + } + continue; + } // Ensure directory separators are consistent string filename = entry.Key; diff --git a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs index 0b78de3a..eb2c98df 100644 --- a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs @@ -75,9 +75,17 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu if (firstFile) firstFile = false; - else + else if (entry.IsSolid) { - isSolid = entry.IsSolid; + // If the RAR is solid and the first entry is password-protected, you won't be able to + // extract the rest of the entries anyway, so just return early. + if (entry.IsEncrypted) + { + if (includeDebug) Console.WriteLine("RAR is password-protected!"); + return false; + } + + isSolid = true; break; } } @@ -200,6 +208,7 @@ public static List FindParts(string firstPart) /// private static bool ExtractNonSolid(RarArchive rarFile, string outDir, bool includeDebug) { + bool encrypted = false; foreach (var entry in rarFile.Entries) { try @@ -215,6 +224,17 @@ private static bool ExtractNonSolid(RarArchive rarFile, string outDir, bool incl // If we have a partial entry due to an incomplete multi-part archive, skip it if (!entry.IsComplete) continue; + + // If the entry is password-protected, skip it + if (entry.IsEncrypted) + { + if (!encrypted) + { + if (includeDebug) Console.WriteLine("Some or all files in RAR are password-protected!"); + encrypted = true; + } + continue; + } // Ensure directory separators are consistent string filename = entry.Key; diff --git a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs index 7b0c1971..edb8e6ba 100644 --- a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs @@ -74,9 +74,17 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu if (firstFile) firstFile = false; - else + else if (entry.IsSolid) { - isSolid = entry.IsSolid; + // If the 7z is solid and the first entry is password-protected, you won't be able to + // extract the rest of the entries anyway, so just return early. + if (entry.IsEncrypted) + { + if (includeDebug) Console.WriteLine("7z is password-protected!"); + return false; + } + + isSolid = true; break; } } @@ -168,6 +176,7 @@ public static List FindParts(string firstPart) /// private static bool ExtractNonSolid(SevenZipArchive sevenZip, string outputDirectory, bool includeDebug) { + bool encrypted = false; foreach (var entry in sevenZip.Entries) { try @@ -183,6 +192,17 @@ private static bool ExtractNonSolid(SevenZipArchive sevenZip, string outputDirec // If we have a partial entry due to an incomplete multi-part archive, skip it if (!entry.IsComplete) continue; + + // If the entry is password-protected, skip it + if (entry.IsEncrypted) + { + if (!encrypted) + { + if (includeDebug) Console.WriteLine("Some or all files in 7z are password-protected!"); + encrypted = true; + } + continue; + } // Ensure directory separators are consistent string filename = entry.Key; From fe6eff2a01b0ca637f8b55af4cf482dfaca6f080 Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Mon, 1 Dec 2025 11:25:48 -0500 Subject: [PATCH 2/4] Fix logic error --- SabreTools.Serialization/Wrappers/RAR.Extraction.cs | 9 +++++++-- SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs index eb2c98df..0e0eb13a 100644 --- a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs @@ -74,8 +74,12 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu continue; if (firstFile) + { firstFile = false; - else if (entry.IsSolid) + continue; + } + + if (entry.IsSolid) { // If the RAR is solid and the first entry is password-protected, you won't be able to // extract the rest of the entries anyway, so just return early. @@ -86,8 +90,9 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu } isSolid = true; - break; } + + break; } catch (Exception ex) { diff --git a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs index edb8e6ba..df3e1331 100644 --- a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs @@ -73,8 +73,12 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu continue; if (firstFile) + { firstFile = false; - else if (entry.IsSolid) + continue; + } + + if (entry.IsSolid) { // If the 7z is solid and the first entry is password-protected, you won't be able to // extract the rest of the entries anyway, so just return early. @@ -85,8 +89,9 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu } isSolid = true; - break; } + + break; } catch (Exception ex) { From e939ee829df308c561e844946599059b2cecd339 Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Tue, 2 Dec 2025 09:15:11 -0500 Subject: [PATCH 3/4] Continues --- SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs | 1 + SabreTools.Serialization/Wrappers/RAR.Extraction.cs | 1 + SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs | 1 + 3 files changed, 3 insertions(+) diff --git a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs index 45259e74..b89a81d6 100644 --- a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs @@ -68,6 +68,7 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu if (includeDebug) Console.WriteLine("Some or all files in zip are password-protected!"); encrypted = true; } + continue; } diff --git a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs index 0e0eb13a..86b8e23f 100644 --- a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs @@ -238,6 +238,7 @@ private static bool ExtractNonSolid(RarArchive rarFile, string outDir, bool incl if (includeDebug) Console.WriteLine("Some or all files in RAR are password-protected!"); encrypted = true; } + continue; } diff --git a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs index df3e1331..667289b1 100644 --- a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs @@ -206,6 +206,7 @@ private static bool ExtractNonSolid(SevenZipArchive sevenZip, string outputDirec if (includeDebug) Console.WriteLine("Some or all files in 7z are password-protected!"); encrypted = true; } + continue; } From 7d3cbcae71718af4cb74f020ec1625a6dfee848d Mon Sep 17 00:00:00 2001 From: HeroponRikiBestest Date: Tue, 2 Dec 2025 09:34:50 -0500 Subject: [PATCH 4/4] Remove bool --- SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs | 7 +------ SabreTools.Serialization/Wrappers/RAR.Extraction.cs | 7 +------ SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs | 7 +------ 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs index b89a81d6..d2c57ebe 100644 --- a/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/PKZIP.Extraction.cs @@ -43,7 +43,6 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu zipFile = ZipArchive.Open(parts, readerOptions); } - bool encrypted = false; foreach (var entry in zipFile.Entries) { try @@ -63,11 +62,7 @@ public bool Extract(string outputDirectory, bool lookForHeader, bool includeDebu // If the entry is password-protected, skip it if (entry.IsEncrypted) { - if (!encrypted) - { - if (includeDebug) Console.WriteLine("Some or all files in zip are password-protected!"); - encrypted = true; - } + if (includeDebug) Console.WriteLine($"File {entry.Key} in zip is password-protected!"); continue; } diff --git a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs index 86b8e23f..c257954f 100644 --- a/SabreTools.Serialization/Wrappers/RAR.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/RAR.Extraction.cs @@ -213,7 +213,6 @@ public static List FindParts(string firstPart) /// private static bool ExtractNonSolid(RarArchive rarFile, string outDir, bool includeDebug) { - bool encrypted = false; foreach (var entry in rarFile.Entries) { try @@ -233,11 +232,7 @@ private static bool ExtractNonSolid(RarArchive rarFile, string outDir, bool incl // If the entry is password-protected, skip it if (entry.IsEncrypted) { - if (!encrypted) - { - if (includeDebug) Console.WriteLine("Some or all files in RAR are password-protected!"); - encrypted = true; - } + if (includeDebug) Console.WriteLine($"File {entry.Key} in RAR is password-protected!"); continue; } diff --git a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs index 667289b1..fb6df68e 100644 --- a/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs +++ b/SabreTools.Serialization/Wrappers/SevenZip.Extraction.cs @@ -181,7 +181,6 @@ public static List FindParts(string firstPart) /// private static bool ExtractNonSolid(SevenZipArchive sevenZip, string outputDirectory, bool includeDebug) { - bool encrypted = false; foreach (var entry in sevenZip.Entries) { try @@ -201,11 +200,7 @@ private static bool ExtractNonSolid(SevenZipArchive sevenZip, string outputDirec // If the entry is password-protected, skip it if (entry.IsEncrypted) { - if (!encrypted) - { - if (includeDebug) Console.WriteLine("Some or all files in 7z are password-protected!"); - encrypted = true; - } + if (includeDebug) Console.WriteLine($"File {entry.Key} in 7z is password-protected!"); continue; }