Fix zlib usage

Data may remain in zlib internal buffers when inflate() returns Z_OK
and avail_out == 0. In that case, inflate has to be called again.

Also, once all the data has been inflated, it returns Z_BUF_ERROR to
signal that the input buffer has been exhausted.

Until now, the way to detect that a packet payload had been completely
decompressed was to check that no data remained on the input buffer
but that didn't account for the case where data remained on the internal
zlib buffers.

That resulted in packets not being completely decompressed and the
missing data reappearing on the next packet, though the bug was masked
by the buffer allocation algorithm most of the time and only manifested
when transferring highly compressible data.

This patch fixes the zlib usage.

Signed-off-by: Salvador <sfandino@yahoo.com>
This commit is contained in:
Salvador 2013-10-15 11:00:52 +02:00 committed by Daniel Stenberg
parent 27f9ac2549
commit 55a8b10ad9

View File

@ -259,12 +259,12 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session,
status = inflate(strm, Z_PARTIAL_FLUSH); status = inflate(strm, Z_PARTIAL_FLUSH);
if (status == Z_OK) { if (status == Z_OK) {
if (! strm->avail_in) { if (strm->avail_out > 0)
/* status is OK and input all used so we're done */ /* status is OK and the output buffer has not been exhausted so we're done */
break; break;
}
} else if (status == Z_BUF_ERROR) { } else if (status == Z_BUF_ERROR) {
/* This is OK, just drop through to grow the buffer */ /* the input data has been exhausted so we are done */
break;
} else { } else {
/* error state */ /* error state */
LIBSSH2_FREE(session, out); LIBSSH2_FREE(session, out);