diff --git a/SafeExamBrowser.Configuration.UnitTests/DataCompression/GZipCompressorTests.cs b/SafeExamBrowser.Configuration.UnitTests/DataCompression/GZipCompressorTests.cs index 309e982d..f13d2a4d 100644 --- a/SafeExamBrowser.Configuration.UnitTests/DataCompression/GZipCompressorTests.cs +++ b/SafeExamBrowser.Configuration.UnitTests/DataCompression/GZipCompressorTests.cs @@ -83,6 +83,16 @@ namespace SafeExamBrowser.Configuration.UnitTests.DataCompression var preview = sut.Peek(compressed, 5); + try + { + var position = compressed.Position; + var length = compressed.Length; + } + catch (ObjectDisposedException) + { + Assert.Fail("Source stream was disposed after previewing data!"); + } + Assert.AreEqual(5, preview.Length); Assert.IsTrue(Encoding.UTF8.GetBytes("A com").SequenceEqual(preview)); } diff --git a/SafeExamBrowser.Configuration/DataCompression/GZipCompressor.cs b/SafeExamBrowser.Configuration/DataCompression/GZipCompressor.cs index 3c8aac99..2d639feb 100644 --- a/SafeExamBrowser.Configuration/DataCompression/GZipCompressor.cs +++ b/SafeExamBrowser.Configuration/DataCompression/GZipCompressor.cs @@ -103,10 +103,9 @@ namespace SafeExamBrowser.Configuration.DataCompression public byte[] Peek(Stream data, int count) { - var stream = new GZipStream(data, CompressionMode.Decompress); - data.Seek(0, SeekOrigin.Begin); + using (var stream = new GZipStream(data, CompressionMode.Decompress, true)) using (var decompressed = new MemoryStream()) { var buffer = new byte[count];