commit ada0ae4b8e972fbdb6a4f0b6854b81177f6c5cf4
Author: Oswald Buddenhagen <o...@users.sf.net>
Date:   Sun Jul 30 18:37:58 2017 +0200

    fix spurious decompression errors
    
    while that's just bad api, inflate() can return Z_BUF_ERROR during
    normal operation.
    
    contrary to the zpipe example and what the documentation implies,
    deflate() actually isn't that braindead. add respective comments.
    
    REFMAIL: cala3aexmjtrl0tamguanpdtnn-_hj0sykoexwzoo6dvainf...@mail.gmail.com

 src/socket.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/socket.c b/src/socket.c
index 4677c67..9357b8c 100644
--- a/src/socket.c
+++ b/src/socket.c
@@ -637,7 +637,9 @@ socket_fill_z( conn_t *sock )
        sock->in_z->next_out = (unsigned char *)buf;
 
        ret = inflate( sock->in_z, Z_SYNC_FLUSH );
-       if (ret != Z_OK && ret != Z_STREAM_END) {
+       /* Z_BUF_ERROR happens here when the previous call both consumed
+        * all input and exactly filled up the output buffer. */
+       if (ret != Z_OK && ret != Z_BUF_ERROR && ret != Z_STREAM_END) {
                error( "Error decompressing data from %s: %s\n", sock->name, 
z_err_msg( ret, sock->in_z ) );
                socket_fail( sock );
                return;
@@ -824,6 +826,9 @@ do_flush( conn_t *conn )
                        conn->out_z->avail_in = 0;
                        conn->out_z->next_out = (uchar *)bc->data + bc->len;
                        conn->out_z->avail_out = buf_avail;
+                       /* Z_BUF_ERROR cannot happen here, as zlib suppresses 
the error
+                        * both upon increasing the flush level (1st iteration) 
and upon
+                        * a no-op after the output buffer was full (later 
iterations). */
                        if ((ret = deflate( conn->out_z, Z_PARTIAL_FLUSH )) != 
Z_OK) {
                                error( "Fatal: Compression error: %s\n", 
z_err_msg( ret, conn->out_z ) );
                                abort();
@@ -892,6 +897,8 @@ socket_write( conn_t *conn, conn_iovec_t *iov, int iovcnt )
                                conn->out_z->avail_in = len;
                                conn->out_z->next_out = (uchar *)bc->data + 
bc->len;
                                conn->out_z->avail_out = buf_avail;
+                               /* Z_BUF_ERROR is impossible here, as the input 
buffer always has data,
+                                * and the output buffer always has space. */
                                if ((ret = deflate( conn->out_z, Z_NO_FLUSH )) 
!= Z_OK) {
                                        error( "Fatal: Compression error: 
%s\n", z_err_msg( ret, conn->out_z ) );
                                        abort();

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
isync-devel mailing list
isync-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to