From 984119c7eedc8c7695345ceeb834276189f86bfc Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Fri, 10 Jun 2022 21:00:04 -0600 Subject: [PATCH] Exit download loop if zero bytes are read. --- Source/AaxDecrypter/NetworkFileStream.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/AaxDecrypter/NetworkFileStream.cs b/Source/AaxDecrypter/NetworkFileStream.cs index e0a6506f..e1159d67 100644 --- a/Source/AaxDecrypter/NetworkFileStream.cs +++ b/Source/AaxDecrypter/NetworkFileStream.cs @@ -221,9 +221,10 @@ namespace AaxDecrypter try { + int bytesRead; do { - var bytesRead = _networkStream.Read(buff, 0, DOWNLOAD_BUFF_SZ); + bytesRead = _networkStream.Read(buff, 0, DOWNLOAD_BUFF_SZ); _writeFile.Write(buff, 0, bytesRead); downloadPosition += bytesRead; @@ -237,7 +238,7 @@ namespace AaxDecrypter downloadedPiece.Set(); } - } while (downloadPosition < ContentLength && !IsCancelled); + } while (downloadPosition < ContentLength && !IsCancelled && bytesRead > 0); _writeFile.Close(); _networkStream.Close();