[System.IO.Compression] Fixed DeflateStream input stream EOF condition.
authorJoao Matos <joao@tritao.eu>
Thu, 27 Oct 2016 18:45:34 +0000 (19:45 +0100)
committerJoao Matos <joao@tritao.eu>
Thu, 27 Oct 2016 21:01:10 +0000 (22:01 +0100)
What was happening is that we set the stream EOF flag to true when we
could not read any more input data, and that made us early out before
fully finishing the processing of the compressed data.

Now the only EOF flag is set to true is if zlib's inflate() has actually
finished processing the data.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=44994#c2.

mcs/class/System/Test/System.IO.Compression/DeflateStreamTest.cs
mcs/class/System/Test/compressed.bin [new file with mode: 0644]
support/zlib-helper.c

index 4fef4c5f4d8f083fcd50ca8a315940ec01bc83c3..17ca231ffb63c366d6e75dc1494d1ee995638f0f 100644 (file)
@@ -432,6 +432,24 @@ namespace MonoTests.System.IO.Compression
 
                        Assert.AreEqual(81942, unZipped.Length);
                }
+
+               [Test]
+               public void Bug44994_InflateByteByByte()
+               {
+                       int byteCount = 0;
+                       using (var fileStream = File.OpenRead(Path.Combine("Test", "compressed.bin")))
+                       {
+                               using (var deflateStream = new DeflateStream(fileStream, CompressionMode.Decompress, false))
+                               {
+                                       while (deflateStream.ReadByte() != -1)
+                                       {
+                                               byteCount++;
+                                       }
+                               }
+                       }
+
+                       Assert.AreEqual(125387, byteCount);
+               }
        }
 }
 
diff --git a/mcs/class/System/Test/compressed.bin b/mcs/class/System/Test/compressed.bin
new file mode 100644 (file)
index 0000000..3098195
Binary files /dev/null and b/mcs/class/System/Test/compressed.bin differ
index 5e07a2e21ce4d90071d4247820ae8cea706accd5..5a33d0f2b8e11ccf96d9efe317e1658fff163b1a 100644 (file)
@@ -195,9 +195,6 @@ ReadZStream (ZStream *stream, guchar *buffer, gint length)
                if (zs->avail_in == 0) {
                        n = stream->func (stream->buffer, BUFFER_SIZE, stream->gchandle);
                        stream->total_in += n;
-                       if (n <= 0) {
-                               stream->eof = TRUE;
-                       }
                        zs->next_in = stream->buffer;
                        zs->avail_in = n < 0 ? 0 : n;
                }