Repository navigation
fix(cli): reject --max-alloc=0 instead of disabling the guard - #7285
Merged
Merged
Conversation
upstream rsync 3.5.0 refuses a max-alloc of 0 in parse_arguments() (options.c:2069-2072) with "max-alloc must be greater than zero". Previously 0 fell through to `if (!max_alloc) max_alloc = SIZE_MAX;`, which removed the per-allocation ceiling entirely - the defence behind the earlier allocation CVEs. The value also arrives from a peer, so a modified or older client could disable a daemon's cap over the wire. oc had the same defect: --max-alloc=0 and RSYNC_MAX_ALLOC=0 both published usize::MAX, on the client path and on the server decode path. parse_max_alloc_argument is the one parser both entry points share, so the check lands there once and covers the flag, the environment default and a peer-forwarded value. The now-unreachable "0 means unlimited" branches in the server decoder and in apply_max_alloc are removed; a library caller that still supplies 0 leaves the standing ceiling in place, matching protocol::set_max_alloc's contract for a zero argument. The 1 MiB minimum message keeps its "or 0 for unlimited" clause because 3.5.0 left parse_size_arg's text unchanged. Also fixes the server-side error rendering for this option, which passed a fully rendered Message where its sibling branches pass bare text and so emitted a doubled "rsync error: ..." envelope.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
upstream rsync 3.5.0 refuses a max-alloc of 0 in parse_arguments() (options.c:2069-2072) with "max-alloc must be greater than zero". Previously 0 fell through to `if (!max_alloc) max_alloc = SIZE_MAX;`, which removed the per-allocation ceiling entirely - the defence behind the earlier allocation CVEs. The value also arrives from a peer, so a modified or older client could disable a daemon's cap over the wire. oc had the same defect: --max-alloc=0 and RSYNC_MAX_ALLOC=0 both published usize::MAX, on the client path and on the server decode path. parse_max_alloc_argument is the one parser both entry points share, so the check lands there once and covers the flag, the environment default and a peer-forwarded value. The now-unreachable "0 means unlimited" branches in the server decoder and in apply_max_alloc are removed; a library caller that still supplies 0 leaves the standing ceiling in place, matching protocol::set_max_alloc's contract for a zero argument. The 1 MiB minimum message keeps its "or 0 for unlimited" clause because 3.5.0 left parse_size_arg's text unchanged. Also fixes the server-side error rendering for this option, which passed a fully rendered Message where its sibling branches pass bare text and so emitted a doubled "rsync error: ..." envelope.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What upstream does
rsync 3.5.0 added a zero check to the
--max-allocblock inoptions.c:parse_arguments()(options.c:2066-2074):In 3.4.4 the
size == 0arm does not exist, so zero fell through toif (!max_alloc) max_alloc = SIZE_MAX;and removed the per-allocationceiling that
my_alloc()enforces - the defence behind the earlierallocation CVEs.
Observable contract mirrored here
max-alloc must be greater than zero(verbatim)goto cleanupreturns 0 fromparse_arguments,main.ccallsoption_error()thenexit_cleanup(RERR_SYNTAX)err_bufand exitsRERR_UNSUPPORTED(clientserver.c:1254-1268)parse_arguments()is shared between roles, so the same check covers theoperator flag,
RSYNC_MAX_ALLOC, and a value a peer forwarded on the wire.testsuite/daemon-max-alloc-zero_test.pyexists precisely because theclient-side test alone does not protect a daemon: an unpatched 3.2.7 client
still forwards
--max-alloc=0.parse_size_arg's "too small" message keeps itsor 0 for unlimitedclause - 3.5.0 left that string untouched even though the caller now
refuses zero. Mirrored verbatim rather than corrected, with the reason
recorded in a comment.
What oc did before (MEASURED)
Against the binary built from
origin/master:Three sites encoded "0 means unlimited":
crates/cli/src/frontend/execution/options/size.rs-MAX_ALLOC_UNLIMITEDreturned zero verbatim
crates/cli/src/frontend/server/run.rs- a forwarded zero calledprotocol::set_max_alloc(usize::MAX)crates/core/src/client/run/mod.rs-apply_max_allocdid the sameShared helper: yes, and it is the right place
Both entry points call one parser,
parse_max_alloc_argument(
crates/cli/src/frontend/execution/options/size.rs) - the client viadrive/options.rs, the server viaserver/run.rs, and the environmentdefault via
arguments/env.rsfeeding the same flag slot. The check is asingle guard there.
It is not a generic numeric-option helper, though.
--block-size=0goes through the sibling
parse_block_size_argumentand legitimately means"use the default" (upstream passes
min_value0 for it), and--bwlimit=0means unlimited upstream as well. So for the sibling 3.5.0 CVEs in this
family - zstd thread count,
MSG_IO_TIMEOUT, xattr expansion, equal-checksumchain length - there is no one place to fix them all; each needs its own
bound at its own decode site. Worth knowing before those tasks start.
Also checked, not fixed
testsuite/daemon-size-arg-overflow_test.pycovers a different bug in thesame function: C99
snprintfreturns the length it would have written, soparse_size_arg's trailingerr_buf[len] = '\n'writes out of bounds when adaemon client sends a multi-kilobyte size value. That is a C string-handling
defect with no analogue in oc -
SizeArgErrorcarries no buffer and themessage is a
format!, so there is nothing to clamp. Not folded in; statedhere rather than silently skipped.
Changes
size.rs- reject zero with upstream's text; deleteMAX_ALLOC_UNLIMITEDserver/run.rs- drop the unreachable unlimited branch; render the errorwith
.text()like every sibling branch, instead of emitting a doubledrsync error: ...envelopecore/client/run/mod.rs- a library-supplied 0 now leaves the standingceiling rather than lifting it, matching
protocol::set_max_allocTests
New
crates/cli/tests/max_alloc_zero_rejected.rsdrives the real binary:client_rejects_max_alloc_zero- exit 1 + upstream textclient_accepts_a_non_zero_max_alloc- positive control;--max-alloc=2Gtransfers and the destination bytes match, so the rejection test cannot
pass because everything is refused
server_rejects_a_peer_forwarded_max_alloc_zero---server ... --max-alloc=0with closed stdin, the wire-supplied case
Unit cells in
size.rsandfrontend/tests/parse_max_alloc.rscover everyspelling of zero (
0,0B,0K,0.0M), theRSYNC_MAX_ALLOC=0path, andkeep the below-1-MiB and above-ceiling rejections pinned. Four pre-existing
tests asserted the old accept-zero behaviour and were inverted.
Verification
Behaviour after the fix, measured: