Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mcs
diff options
context:
space:
mode:
authorFilip Navara <filip.navara@gmail.com>2018-08-28 16:36:24 +0300
committerMarek Safar <marek.safar@gmail.com>2018-09-06 19:38:22 +0300
commitc63e12669d6c080dfe37c957f74c20d8b436aa83 (patch)
treec0d66d454fa9d8bb35932eb47103cdcf19a76d2f /mcs
parentd21d00b366cbf9115248c40bd8c72d4db717fd63 (diff)
Fix DeflateStream handling of zero-length reads from underlying stream.
Diffstat (limited to 'mcs')
-rw-r--r--mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs55
1 files changed, 55 insertions, 0 deletions
diff --git a/mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs b/mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs
index 3681b5cc25c..9d54e0f6015 100644
--- a/mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs
+++ b/mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs
@@ -480,6 +480,61 @@ namespace MonoTests.System.IO.Compression
Assert.AreEqual(125387, byteCount);
}
+
+ [Test]
+ public void Issue10054_ZeroRead()
+ {
+ // "HelloWorld" as UTF8/DeflateStream(...,CompressionMode.Compress)
+ var buffer = new byte[] { 243, 72, 205, 201, 201, 15, 207, 47, 202, 73, 1, 0 };
+ var mem = new MemoryStream(buffer);
+ var chu = new ChunkedReader(mem);
+ var def = new DeflateStream(chu, CompressionMode.Decompress);
+
+ var buffer2 = new byte[4096];
+ int read2 = 0;
+
+ chu.limit = 3;
+ read2 += def.Read(buffer2, read2, buffer2.Length - read2);
+ chu.limit = 100;
+ read2 += def.Read(buffer2, read2, buffer2.Length - read2);
+
+ var res = Encoding.UTF8.GetString(buffer2, 0, read2);
+ Assert.AreEqual("HelloWorld", res);
+ }
+
+ public class ChunkedReader : Stream
+ {
+ public int limit = 0;
+ private Stream baseStream;
+
+ public ChunkedReader(Stream baseStream)
+ {
+ this.baseStream = baseStream;
+ }
+
+ public override int Read(byte[] buffer, int offset, int count)
+ {
+ int read = baseStream.Read(buffer, offset, Math.Min(count, this.limit));
+ this.limit -= read;
+ return read;
+ }
+
+ public override void Flush() => baseStream.Flush();
+ public override long Seek(long offset, SeekOrigin origin) => baseStream.Seek(offset, origin);
+ public override void SetLength(long value) => baseStream.SetLength(value);
+ public override void Write(byte[] buffer, int offset, int count) => baseStream.Write(buffer, offset, count);
+
+ public override bool CanRead => baseStream.CanRead;
+ public override bool CanSeek => baseStream.CanSeek;
+ public override bool CanWrite => baseStream.CanWrite;
+ public override long Length => baseStream.Length;
+
+ public override long Position
+ {
+ get => baseStream.Position;
+ set => baseStream.Position = value;
+ }
+ }
}
}