[System.IO.Compression] Fixed potential bug when keeping track of total read bytes...
authorJoao Matos <joao@tritao.eu>
Thu, 27 Oct 2016 19:35:20 +0000 (20:35 +0100)
committerJoao Matos <joao@tritao.eu>
Thu, 27 Oct 2016 21:01:21 +0000 (22:01 +0100)
This didn't manifest as a bug, to to be on the safe side, replicate the behavior
introduced in https://github.com/mono/mono/commit/b4d5016b5e42fec226d93fd13260b6cac80eb384
and use the same approach when calculating the total of the read bytes of the input stream.

support/zlib-helper.c

index 5a33d0f2b8e11ccf96d9efe317e1658fff163b1a..9dcebc7e967d6b04e9d8780c6cf7807e51bac228 100644 (file)
@@ -194,9 +194,10 @@ ReadZStream (ZStream *stream, guchar *buffer, gint length)
        while (zs->avail_out > 0) {
                if (zs->avail_in == 0) {
                        n = stream->func (stream->buffer, BUFFER_SIZE, stream->gchandle);
+                       n = n < 0 ? 0 : n;
                        stream->total_in += n;
                        zs->next_in = stream->buffer;
-                       zs->avail_in = n < 0 ? 0 : n;
+                       zs->avail_in = n;
                }
 
                if (zs->avail_in == 0 && zs->total_in == 0)