Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Added additional validation for rar volumes.
nzbdav-dev79532111f072
diff --git a/backend/Queue/FileAggregators/RarAggregator.cs b/backend/Queue/FileAggregators/RarAggregator.csindex 59e8b43b..ece67757 100644--- a/backend/Queue/FileAggregators/RarAggregator.cs+++ b/backend/Queue/FileAggregators/RarAggregator.cs@@ -36,6 +36,10 @@ public class RarAggregator(DavDatabaseClient dbClient, DavItem mountDirectory, bforeach (var archiveFile in archiveFiles){+ // Ensure we have all volumes necessary for this file.+ ValidateVolumes(archiveFile.Value);++ // Initialize dav-item fieldsvar pathWithinArchive = archiveFile.Key;var fileParts = SortByPartNumber(archiveFile.Value);var aesParams = fileParts.Select(x => x.AesParams).FirstOrDefault(x => x != null);@@ -99,13 +103,25 @@ public class RarAggregator(DavDatabaseClient dbClient, DavItem mountDirectory, b.ToArray();}+ private static void ValidateVolumes(List<RarProcessor.StoredFileSegment> storedFileSegments)+ {+ if (storedFileSegments.Count == 0) return;+ var distinctUncompressedSizes = storedFileSegments.Select(x => x.FileUncompressedSize).Distinct().ToList();+ if (distinctUncompressedSizes.Count != 1)+ throw new InvalidDataException("Inconsistent rar file size detected.");+ var expected = distinctUncompressedSizes[0];+ var actual = storedFileSegments.Sum(x => x.ByteRangeWithinPart.Count);+ if (Math.Abs(actual - expected) > 16)+ throw new InvalidDataException("Missing rar volumes detected.");+ }+[SuppressMessage("ReSharper", "PossibleMultipleEnumeration")]private static void ValidatePartNumbers(IEnumerable<int> partNumbers){var count = partNumbers.Count();var uniqueCount = partNumbers.Distinct().Count();if (count != uniqueCount)- throw new InvalidFormatException("Rar archive has duplicate volume numbers.");+ throw new InvalidDataException("Rar archive has duplicate volume numbers.");}private static int GetNormalizedPartNumber(RarProcessor.PartNumber partNumber, int? delta)diff --git a/backend/Queue/FileProcessors/RarProcessor.cs b/backend/Queue/FileProcessors/RarProcessor.csindex 7f77348d..2f137ca1 100644--- a/backend/Queue/FileProcessors/RarProcessor.cs+++ b/backend/Queue/FileProcessors/RarProcessor.cs@@ -39,6 +39,7 @@ public class RarProcessor(x.GetAdditionalDataSize()),AesParams = x.GetAesParams(password),+ FileUncompressedSize = x.GetUncompressedSize(),ReleaseDate = fileInfo.ReleaseDate,}).ToArray(),};@@ -125,6 +126,8 @@ public class RarProcessor(public required string PathWithinArchive { get; init; }public required LongRange ByteRangeWithinPart { get; init; }public required AesParams? AesParams { get; init; }++ public required long FileUncompressedSize { get; init; }}public record PartNumber