]> git.ipfire.org Git - thirdparty/rsync.git/commit
token: drain the matched-block insert deflate (#951)
authorAndrew Tridgell <andrew@tridgell.net>
Thu, 4 Jun 2026 05:49:14 +0000 (15:49 +1000)
committerAndrew Tridgell <andrew@tridgell.net>
Fri, 5 Jun 2026 00:38:03 +0000 (10:38 +1000)
commitc5b7ea0bd23ffe73d87d0db3f92f640e31ec18a4
tree0fd34dedb8d5e832996994bb468251ad59446f4d
parent0b08fa4285538dca500186aec075d0cbca67aa26
token: drain the matched-block insert deflate (#951)

send_deflated_token() adds a matched block to the compressor history with
deflate(Z_INSERT_ONLY).  Our bundled zlib implements Z_INSERT_ONLY (it
produces no output and consumes the input in one call), but a build
against a system zlib lacks it and falls back to Z_SYNC_FLUSH (see the top
of the file), which emits a flush block into obuf.  For a large
incompressible matched token that block exceeds AVAIL_OUT_SIZE(CHUNK_SIZE),
so deflate returned with avail_in != 0 and the transfer aborted:

    "deflate on token returned 0 (N bytes left)"  at token.c

The insert output is never sent -- the receiver rebuilds the matching
history itself in see_deflate_token() -- so loop, resetting the output
buffer, and discard it.  Drain with the same condition as the data loop
above: until the input is consumed AND avail_out != 0.  Stopping at
avail_in == 0 alone can leave pending output in the deflate stream (a
full output buffer with bytes still buffered), which would then be emitted
by the next real deflate send and corrupt the stream.  A bundled-zlib
build still finishes in one iteration.

Fixes: #951
testsuite/compress-zlib-insert_test.py [new file with mode: 0644]
token.c