diff --git a/src/SharpCompress/Archives/GZip/GZipArchive.cs b/src/SharpCompress/Archives/GZip/GZipArchive.cs index 58f98ab9..4437ff57 100644 --- a/src/SharpCompress/Archives/GZip/GZipArchive.cs +++ b/src/SharpCompress/Archives/GZip/GZipArchive.cs @@ -89,6 +89,12 @@ public class GZipArchive : AbstractWritableArchive public static GZipArchive Open(Stream stream, ReaderOptions? readerOptions = null) { stream.CheckNotNull(nameof(stream)); + + if (stream is not { CanSeek: true }) + { + throw new ArgumentException("Stream must be seekable", nameof(stream)); + } + return new GZipArchive( new SourceStream(stream, _ => null, readerOptions ?? new ReaderOptions()) ); diff --git a/src/SharpCompress/Archives/Rar/RarArchive.cs b/src/SharpCompress/Archives/Rar/RarArchive.cs index d84d0edc..ee4be60e 100644 --- a/src/SharpCompress/Archives/Rar/RarArchive.cs +++ b/src/SharpCompress/Archives/Rar/RarArchive.cs @@ -131,6 +131,12 @@ public class RarArchive : AbstractArchive public static RarArchive Open(Stream stream, ReaderOptions? options = null) { stream.CheckNotNull(nameof(stream)); + + if (stream is not { CanSeek: true }) + { + throw new ArgumentException("Stream must be seekable", nameof(stream)); + } + return new RarArchive(new SourceStream(stream, _ => null, options ?? new ReaderOptions())); } diff --git a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs index eabc317e..323f07ac 100644 --- a/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs +++ b/src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs @@ -92,6 +92,12 @@ public class SevenZipArchive : AbstractArchive null, readerOptions ?? new ReaderOptions()) ); diff --git a/src/SharpCompress/Archives/Tar/TarArchive.cs b/src/SharpCompress/Archives/Tar/TarArchive.cs index fdf8cd42..2c9c64c7 100644 --- a/src/SharpCompress/Archives/Tar/TarArchive.cs +++ b/src/SharpCompress/Archives/Tar/TarArchive.cs @@ -90,6 +90,12 @@ public class TarArchive : AbstractWritableArchive public static TarArchive Open(Stream stream, ReaderOptions? readerOptions = null) { stream.CheckNotNull(nameof(stream)); + + if (stream is not { CanSeek: true }) + { + throw new ArgumentException("Stream must be seekable", nameof(stream)); + } + return new TarArchive( new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions()) ); diff --git a/src/SharpCompress/Archives/Zip/ZipArchive.cs b/src/SharpCompress/Archives/Zip/ZipArchive.cs index 85130f70..79cdcf3e 100644 --- a/src/SharpCompress/Archives/Zip/ZipArchive.cs +++ b/src/SharpCompress/Archives/Zip/ZipArchive.cs @@ -111,6 +111,12 @@ public class ZipArchive : AbstractWritableArchive public static ZipArchive Open(Stream stream, ReaderOptions? readerOptions = null) { stream.CheckNotNull(nameof(stream)); + + if (stream is not { CanSeek: true }) + { + throw new ArgumentException("Stream must be seekable", nameof(stream)); + } + return new ZipArchive( new SourceStream(stream, i => null, readerOptions ?? new ReaderOptions()) ); diff --git a/src/SharpCompress/packages.lock.json b/src/SharpCompress/packages.lock.json index b0c97ca6..116a1190 100644 --- a/src/SharpCompress/packages.lock.json +++ b/src/SharpCompress/packages.lock.json @@ -345,4 +345,4 @@ } } } -} \ No newline at end of file +}