Skip to content

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

C#

Fixed integer overflow bug within LimitedLengthStream.

nzbdav-dev2f4c3f417b8c
diff --git a/backend/Streams/LimitedLengthStream.cs b/backend/Streams/LimitedLengthStream.cs
index 576d5467..cd74ffd4 100644
--- a/backend/Streams/LimitedLengthStream.cs
+++ b/backend/Streams/LimitedLengthStream.cs
@@ -21,8 +21,8 @@ public class LimitedLengthStream(Stream stream, long length) : Stream
return 0;
// Calculate how many bytes we can still read
- var remainingBytes = (int)(length - _position);
- var bytesToRead = Math.Min(remainingBytes, buffer.Length);
+ var remainingBytes = length - _position;
+ var bytesToRead = (int)Math.Min(remainingBytes, buffer.Length);
// Read from the underlying stream
var bytesRead = await stream.ReadAsync(buffer[..bytesToRead], cancellationToken);