From 32b1ec32c6e9689061716d21cde552e6319c0310 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Dec 2025 14:32:38 +0000 Subject: [PATCH 1/5] Initial plan 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 2/5] 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; } From d614beb9eb6992ed169963a0c96db52a3b1092c0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Dec 2025 14:41:44 +0000 Subject: [PATCH 3/5] Add explanatory comments for CanSeek checks and try-catch blocks Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- src/SharpCompress/IO/SharpCompressStream.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/SharpCompress/IO/SharpCompressStream.cs b/src/SharpCompress/IO/SharpCompressStream.cs index 5cb8a45c..0ec15136 100644 --- a/src/SharpCompress/IO/SharpCompressStream.cs +++ b/src/SharpCompress/IO/SharpCompressStream.cs @@ -57,7 +57,9 @@ public class SharpCompressStream : Stream, IStreamStack { ValidateBufferState(); // Add here } - // Check CanSeek before accessing Position to avoid exception overhead + // Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams. + // Keep try-catch as defensive programming since some streams may report CanSeek=true + // but still throw on Position access in certain edge cases. if (Stream.CanSeek) { try @@ -144,7 +146,9 @@ public class SharpCompressStream : Stream, IStreamStack _readOnly = !Stream.CanSeek; ((IStreamStack)this).SetBuffer(bufferSize, forceBuffer); - // Check CanSeek before accessing Position to avoid exception overhead + // Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams. + // Keep try-catch as defensive programming since some streams may report CanSeek=true + // but still throw on Position access in certain edge cases. if (stream.CanSeek) { try From 6991900eb0f398c940d54856bd554ae85350e774 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 23 Dec 2025 15:01:41 +0000 Subject: [PATCH 4/5] Remove try/catch blocks, just check CanSeek as requested Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com> --- src/SharpCompress/IO/SharpCompressStream.cs | 36 ++------------------- 1 file changed, 2 insertions(+), 34 deletions(-) diff --git a/src/SharpCompress/IO/SharpCompressStream.cs b/src/SharpCompress/IO/SharpCompressStream.cs index 0ec15136..131ea49c 100644 --- a/src/SharpCompress/IO/SharpCompressStream.cs +++ b/src/SharpCompress/IO/SharpCompressStream.cs @@ -58,23 +58,7 @@ public class SharpCompressStream : Stream, IStreamStack ValidateBufferState(); // Add here } // Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams. - // Keep try-catch as defensive programming since some streams may report CanSeek=true - // but still throw on Position access in certain edge cases. - if (Stream.CanSeek) - { - try - { - _internalPosition = Stream.Position; - } - catch - { - _internalPosition = 0; - } - } - else - { - _internalPosition = 0; - } + _internalPosition = Stream.CanSeek ? Stream.Position : 0; } } } @@ -147,23 +131,7 @@ public class SharpCompressStream : Stream, IStreamStack ((IStreamStack)this).SetBuffer(bufferSize, forceBuffer); // Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams. - // Keep try-catch as defensive programming since some streams may report CanSeek=true - // but still throw on Position access in certain edge cases. - if (stream.CanSeek) - { - try - { - _baseInitialPos = stream.Position; - } - catch - { - _baseInitialPos = 0; - } - } - else - { - _baseInitialPos = 0; - } + _baseInitialPos = stream.CanSeek ? stream.Position : 0; #if DEBUG_STREAMS this.DebugConstruct(typeof(SharpCompressStream)); From 4dbe0b91f129b5fdd5fd8fb8c3d1c5a007fc88f3 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Tue, 23 Dec 2025 15:06:24 +0000 Subject: [PATCH 5/5] Update src/SharpCompress/IO/SharpCompressStream.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/SharpCompress/IO/SharpCompressStream.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SharpCompress/IO/SharpCompressStream.cs b/src/SharpCompress/IO/SharpCompressStream.cs index 131ea49c..185a8766 100644 --- a/src/SharpCompress/IO/SharpCompressStream.cs +++ b/src/SharpCompress/IO/SharpCompressStream.cs @@ -131,7 +131,7 @@ public class SharpCompressStream : Stream, IStreamStack ((IStreamStack)this).SetBuffer(bufferSize, forceBuffer); // Check CanSeek before accessing Position to avoid exception overhead on non-seekable streams. - _baseInitialPos = stream.CanSeek ? stream.Position : 0; + _baseInitialPos = Stream.CanSeek ? Stream.Position : 0; #if DEBUG_STREAMS this.DebugConstruct(typeof(SharpCompressStream));