From: João Matos Date: Tue, 16 Dec 2014 18:54:19 +0000 (+0000) Subject: [System.IO.Compression] Fixed DeflateStream native error when handling empty input. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=b5ddc30ebc05f4ac3ec0ab827b9d5bdecaacd368;p=mono.git [System.IO.Compression] Fixed DeflateStream native error when handling empty input. Bug: https://bugzilla.xamarin.com/show_bug.cgi?id=22346 --- diff --git a/mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs b/mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs index 27312640f5e..fb26433f47d 100644 --- a/mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs +++ b/mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs @@ -91,6 +91,17 @@ namespace MonoTests.System.IO.Compression decompressing.Close(); } + // https://bugzilla.xamarin.com/show_bug.cgi?id=22346 + [Test] + public void CheckEmptyRead () + { + byte [] dummy = new byte[1]; + byte [] data = new byte[0]; + MemoryStream backing = new MemoryStream (data); + DeflateStream compressing = new DeflateStream (backing, CompressionMode.Decompress); + compressing.Read (dummy, 0, 1); + } + [Test] [ExpectedException (typeof (ArgumentNullException))] public void CheckNullRead () diff --git a/support/zlib-helper.c b/support/zlib-helper.c index d0911fc0764..83455413b36 100644 --- a/support/zlib-helper.c +++ b/support/zlib-helper.c @@ -188,6 +188,9 @@ ReadZStream (ZStream *stream, guchar *buffer, gint length) zs->avail_in = n; } + if (zs->avail_in == 0 && zs->total_in == 0) + return Z_STREAM_END; + status = inflate (stream->stream, Z_SYNC_FLUSH); if (status == Z_STREAM_END) { stream->eof = TRUE;