isync

mailbox synchronization program
git clone https://git.code.sf.net/p/isync/isync
Log | Files | Refs | README | LICENSE

commit ada0ae4b8e972fbdb6a4f0b6854b81177f6c5cf4
parent 366ed7d7621f70afc761166bde330aac32e1b2cb
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date:   Sun, 30 Jul 2017 18:37:58 +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-_HJ0sYkOEXWzoO6DVaiNFUHQ@mail.gmail.com

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

diff --git 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();