Skip to content

Usenet streaming with a WebDAV server and a SABnzbd-compatible API

C#

Add message for unsupported password-protected 7z archives.

nzbdav-deva75bc6ad5621
diff --git a/backend/Exceptions/PasswordProtected7zException.cs b/backend/Exceptions/PasswordProtected7zException.cs
new file mode 100644
index 00000000..f2d2ced4
--- /dev/null
+++ b/backend/Exceptions/PasswordProtected7zException.cs
@@ -0,0 +1,5 @@
+namespace NzbWebDAV.Exceptions;
+
+public class PasswordProtected7zException(string message) : NonRetryableDownloadException(message)
+{
+}
\ No newline at end of file
diff --git a/backend/Utils/SevenZipUtil.cs b/backend/Utils/SevenZipUtil.cs
index 3e06adae..cd170d67 100644
--- a/backend/Utils/SevenZipUtil.cs
+++ b/backend/Utils/SevenZipUtil.cs
@@ -1,4 +1,5 @@
-using NzbWebDAV.Extensions;
+using NzbWebDAV.Exceptions;
+using NzbWebDAV.Extensions;
using NzbWebDAV.Models;
using NzbWebDAV.Streams;
using SharpCompress.Archives.SevenZip;
@@ -16,11 +17,18 @@ public static class SevenZipUtil
public static List<SevenZipEntry> GetSevenZipEntries(Stream stream)
{
- using var archive = SevenZipArchive.Open(stream);
- return archive.Entries
- .Where(x => !x.IsDirectory)
- .Select((entry, index) => new SevenZipEntry(entry, archive, index))
- .ToList();
+ try
+ {
+ using var archive = SevenZipArchive.Open(stream);
+ return archive.Entries
+ .Where(x => !x.IsDirectory)
+ .Select((entry, index) => new SevenZipEntry(entry, archive, index))
+ .ToList();
+ }
+ catch (CryptographicException e)
+ {
+ throw new PasswordProtected7zException("Password-protected 7z archives are not supported");
+ }
}
public class SevenZipEntry(SevenZipArchiveEntry entry, SevenZipArchive archive, int index)