From 253a46d458200530fb2def55f505af84d9d52eae Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Dec 2025 14:38:11 +0000 Subject: [PATCH] Fix NotSupportedException in SharpCompressStream by checking CanSeek Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- src/SharpCompress/IO/SharpCompressStream.cs | 28 ++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/SharpCompress/IO/SharpCompressStream.cs b/src/SharpCompress/IO/SharpCompressStream.cs index 00c0ada2..5cb8a45c 100644 --- a/src/SharpCompress/IO/SharpCompressStream.cs +++ b/src/SharpCompress/IO/SharpCompressStream.cs @@ -57,11 +57,19 @@ public class SharpCompressStream : Stream, IStreamStack { ValidateBufferState(); // Add here } - try + // Check CanSeek before accessing Position to avoid exception overhead + if (Stream.CanSeek) { - _internalPosition = Stream.Position; + try + { + _internalPosition = Stream.Position; + } + catch + { + _internalPosition = 0; + } } - catch + else { _internalPosition = 0; } @@ -136,11 +144,19 @@ public class SharpCompressStream : Stream, IStreamStack _readOnly = !Stream.CanSeek; ((IStreamStack)this).SetBuffer(bufferSize, forceBuffer); - try + // Check CanSeek before accessing Position to avoid exception overhead + if (stream.CanSeek) { - _baseInitialPos = stream.Position; + try + { + _baseInitialPos = stream.Position; + } + catch + { + _baseInitialPos = 0; + } } - catch + else { _baseInitialPos = 0; }