Skip to content

token: drain the matched-block insert deflate#962

Open
tridge wants to merge 1 commit into
RsyncProject:masterfrom
tridge:pr-deflate-error
Open

token: drain the matched-block insert deflate#962
tridge wants to merge 1 commit into
RsyncProject:masterfrom
tridge:pr-deflate-error

Conversation

@tridge
Copy link
Copy Markdown
Member

@tridge tridge commented Jun 4, 2026

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 in-compressible 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 fix is to loop in the drain, being careful to handle different chunk sizes.

Fixes: #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: RsyncProject#951
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

error in rsync protocol data stream (code 12) at token.c(490) [sender=3.4.3]

1 participant