From 55a8b10ad9b873ca54a5f0d8abef2fa6b944d57e Mon Sep 17 00:00:00 2001 From: Salvador Date: Tue, 15 Oct 2013 11:00:52 +0200 Subject: [PATCH] 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 --- src/comp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/comp.c b/src/comp.c index 4593ce4..c9226ed 100644 --- a/src/comp.c +++ b/src/comp.c @@ -259,12 +259,12 @@ comp_method_zlib_decomp(LIBSSH2_SESSION * session, status = inflate(strm, Z_PARTIAL_FLUSH); if (status == Z_OK) { - if (! strm->avail_in) { - /* status is OK and input all used so we're done */ + if (strm->avail_out > 0) + /* status is OK and the output buffer has not been exhausted so we're done */ break; - } } 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 { /* error state */ LIBSSH2_FREE(session, out);