From d8104a4d7cb2ff6c9817d5472f7761c7dadb9eb8 Mon Sep 17 00:00:00 2001 From: Michael Bucari-Tovo Date: Tue, 25 Nov 2025 12:28:47 -0700 Subject: [PATCH] Check is stream is disposed before reading position. --- Source/AaxDecrypter/AudiobookDownloadBase.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Source/AaxDecrypter/AudiobookDownloadBase.cs b/Source/AaxDecrypter/AudiobookDownloadBase.cs index f439955e..d807c901 100644 --- a/Source/AaxDecrypter/AudiobookDownloadBase.cs +++ b/Source/AaxDecrypter/AudiobookDownloadBase.cs @@ -26,7 +26,17 @@ namespace AaxDecrypter protected string OutputDirectory { get; } public IDownloadOptions DownloadOptions { get; } protected NetworkFileStream InputFileStream => NfsPersister.NetworkFileStream; - protected virtual long InputFilePosition => InputFileStream.Position; + protected virtual long InputFilePosition + { + get + { + //Use try/catch instread of checking CanRead to avoid + //a race with the background download completing + //between the check and the Position call. + try { return InputFileStream.Position; } + catch { return InputFileStream.Length; } + } + } private bool downloadFinished; private NetworkFileStreamPersister? m_nfsPersister;