[System.IO.Compression] Fixed DeflateStream native error when handling empty input.
authorJoão Matos <joao@tritao.eu>
Tue, 16 Dec 2014 18:54:19 +0000 (18:54 +0000)
committerJoão Matos <joao@tritao.eu>
Tue, 16 Dec 2014 18:56:24 +0000 (18:56 +0000)
Bug: https://bugzilla.xamarin.com/show_bug.cgi?id=22346

mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs
support/zlib-helper.c

index 27312640f5ecb49b54808a09dbb5e52e5ee61fde..fb26433f47d5475535ba74d5f9aac1e508ce50df 100644 (file)
@@ -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 ()
index d0911fc07647cd6fb03dc61c10f5c8b783ad0998..83455413b3647915ae8cc3cd0ac8e025cf5823be 100644 (file)
@@ -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;