Repository navigation
fix(protocol): reject a modern NDX that overflows a signed file index - #7630
Merged
Merged
Conversation
`read_ndx` accumulated the peer-supplied diff forms in `i32`, so a stream
that drives the running index past `i32::MAX` panicked under debug overflow
checks and wrapped silently in release. Both arms are reachable from bytes
the peer fully controls.
Upstream does neither. `io.c:2574-2578` accumulates every arm into a
`uint32`, where the overflow is defined, and `io.c:2582-2586` then refuses
anything above `MAX_INT32` before narrowing:
if (unum > (uint32)MAX_INT32) {
rprintf(FERROR, "Invalid file index: %lu [%s]\n", ...);
exit_cleanup(RERR_PROTOCOL);
}
Its own comment at `io.c:2579-2581` gives the reason: the value is used
unchecked as a file-list index, so it is rejected here rather than at every
downstream consumer.
oc ported the sibling range check (`rsync.c`'s `Invalid file index: %d
(%d - %d)`, applied later against the materialised list) but not this
decode-time bound. The two are different guards; this one runs first and on
a different quantity.
The unsigned accumulation is as load-bearing as the bound, so both land
together, funnelled through one `ndx_from_unsigned` owner rather than
repeated at the four call sites. `protocol_violation` gives `RERR_PROTOCOL`
(2), matching `exit_cleanup(RERR_PROTOCOL)`.
Found by `modern_ndx_sequential_never_panics`, which is randomised and so
can surface on any PR; the minimal input it reduced to is pinned as a
regression test. Mutating the bound to never fire reddens that pin with
`left: -2147483648` — the wrapped index, i.e. the silent-corruption
outcome a release build would have taken — while the ordinary-diff
companion stays green.
The three `io.c` citations on the decode helpers were 3.4.4-era and no
longer resolved; retargeted at the 3.5.0 pin in the same change.
protocol: 3780 lib tests, 76 proptest cells, fmt clean.
oferchen
added a commit
that referenced
this pull request
Sep 2, 2026
… merged PRs (#7634) * docs(rustdoc): reach the public items rustdoc could not see, and gate the class Two halves of the same question - is what a public item says actually reachable from `cargo doc`? Half 1: seven `//` comment blocks documented a `pub` item, so their text never reached the generated docs. Found positionally, not by content: a `//` run whose next non-attribute line declares a `pub` item. A census keyed on comment CONTENT is false-positive dominated; this one is mechanical. Nine sites matched; two are DELIBERATELY left as `//`, because they document the `#[cfg_attr]` / `#[allow]` attribute directly beneath them rather than the item - `local_copy/overrides.rs` and `local_copy/plan/report.rs`. Promoting those would attach a lint rationale to a public surface as if it described the surface. Text is preserved verbatim, upstream citations included (`generator.c:2149` on the obstacle module). The only rewrite is `socket_options/consts.rs`, where one group note covered two constants: split per item, matching the file's own house style where every other const already carries `///`. Half 2: five intra-doc links could not resolve in a DEFAULT build, and the existing gate is structurally unable to see them. crates/fast_io/src/lib.rs, ewma.rs (x4) -> `adaptive_dispatch`, gated by the off-by-default `adaptive-basis-dispatch` feature crates/rsync_io/.../sync_bridge.rs -> `crate::channel_adapter`, gated by the off-by-default `async-ssh` feature crates/fast_io/src/confinement.rs -> `PinnedRoot`, a PRIVATE struct plus one already on the branch in `module_list/types.rs`, where the link was `Transport::Quic` (the `quic` feature) and its surrounding prose still described the variant as unbuilt. Every crate denies `rustdoc::broken_intra_doc_links`, so each of these is a hard `cargo doc` failure, not a warning. MEASURED on the pristine base: cargo doc --no-deps --workspace -> 7 errors, `fast_io` and `rsync_io` could not be documented cargo doc --no-deps --workspace --all-features -> clean That gap is the whole point. Under `--all-features` the gated items EXIST, so the link resolves and the gate is green; in a default build the item is not compiled at all. `ci.yml`'s `rustdoc-links` job runs only `--all-features`, deliberately mirroring `pages.yml` - which is right for the question Pages asks and cannot ask this one. So the fix is paired with a SECOND step on default features, and neither subsumes the other: `crates/fast_io/src/io_uring` is `cfg(all(target_os = "linux", feature = "io_uring"))` and only the all-features run compiles it. The names stay in backticks with the reason stated at each site, rather than being deleted or the links made conditional - the prose still says what it said, and the next reader learns why it is not a link. After: both invocations document all 25 crates cleanly, 0 errors. fmt clean; clippy on the five touched crates reports no new diagnostics. * docs(changelog): record the ten pull requests merged since the last sweep #7624 brought the Unreleased section up to #7620 and then stopped being true: #7621-#7632 landed after it, of which #7624 is itself that changelog pass and #7628 was never merged. Ten entries were missing. Each is placed in the subsection its change belongs to rather than appended in number order, and #7625 is SPLIT across two, because it is two changes: wiring `--force` is a receiver fix, and the synthetic-transfer-root guard that wiring made necessary is a peer-supplied input bound. Filing it once under either heading would have hidden whichever half the reader was looking for. Security / peer-supplied input bounds #7625 (guard half), #7630 Fixed / transfer and receiver #7622, #7625 (--force half), #7627 Fixed / daemon #7629 Testing and CI #7621, #7623, #7632 Documentation #7626, #7631 Wording is taken from each merge commit's own body, not from its title - the titles compress away the part a reader needs. #7629's title says "keep a dead name converter apart from an unknown name"; what makes it worth an entry is that five outcomes collapsed into one `None` and the merge failed OPEN on exactly the mechanism an operator installs to take ownership decisions away from the peer.
oferchen
added a commit
that referenced
this pull request
Sep 8, 2026
… per rsync.c:436-444 (#7744) upstream: rsync.c:436-444 - inside read_ndx_and_attrs(), once the attribute tail has decoded ITEM_TRANSFER, `i = ndx - cur_flist->ndx_start; if (i < 0 || !S_ISREG(cur_flist->files[i]->mode))` prints received request to transfer non-regular file: %d [%s] and aborts with exit_cleanup(RERR_PROTOCOL). The guard runs on BOTH ends that read a request/echo. oc had no equivalent on either read path: the sender's request loop fell through to a silent `!file_entry.is_file()` skip (no diagnostic, no exit code), and the receiver's echo read serviced the frame. Placement: the receiver's half lives in the shared primitive (ndx_stream::read_ndx_and_attrs) behind a new non-defaulted FlistMarkerSink::ndx_is_regular_file, so every consumer of the primitive is covered by one owner; the sender's request read is open-coded in transfer_loop.rs and applies the same predicate at its attrs read, sharing ndx_stream::non_regular_transfer_request so the diagnostic has one owner. No third NDX->entry resolver is introduced: the sender resolves through NdxMap (resolve_itemize_ndx), the receiver through wire_to_flat_ndx. What existing gates already covered, and what is new: - #7365 refuses every stray NEGATIVE wire NDX; upstream rejects those at rsync.c:344-354, before this guard, so there is no overlap - a negative NDX never reaches the check on either side. - #7630 refuses a modern NDX that overflows a signed file index at the codec, also before the guard. - upstream's `i < 0` residual (a non-negative NDX below the current list's ndx_start, i.e. the INC_RECURSE gap NDX) is refused by the S_ISREG half here: resolve_itemize_ndx maps the gap to the owning *directory* entry, so an ITEM_TRANSFER gap frame fails the regular-file test exactly where upstream fails i < 0. An index past the end of the list stays with its existing owners (validate_file_index on the sender, the echo-ordering check on the receiver, mirroring upstream's earlier flist_for_ndx abort), so this guard never claims a range fault with the non-regular diagnostic. - The NEW substance is the S_ISREG check itself, on both read sites. Ordering consequence, pinned by tests: an ITEM_TRANSFER frame naming a CLEARED slot is now refused by this guard (a cleared entry's zeroed mode is not S_ISREG), exactly as upstream, where rsync.c:436-444 runs before recv_files()'s F_IS_ACTIVE test (receiver.c:871-881). The cleared-entry diagnostic keeps owning non-transfer frames. The module doc's ":420-428" citation had drifted against the pinned 3.5.0 tree and claimed the guard "stays with their current owners"; both corrected. The requesting-side polite skip in the generator is untouched. Mutation proof: disabling the primitive guard fails exactly item_transfer_frame_for_non_regular_entry_is_refused_with_upstream_wording, non_regular_transfer_echo_is_refused_with_upstream_wording and cleared_slot_under_item_transfer_reports_the_non_regular_guard (16 sibling tests stay green); disabling the sender-site guard fails exactly sender_refuses_transfer_request_for_a_symlink_entry and sender_refuses_transfer_request_for_a_directory_entry (17 stay green). Both mutations reverted. transfer: 2494 run, 2494 passed.
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.
The defect
read_ndxaccumulated the peer-supplied diff forms ini32:A stream that drives the running index near
i32::MAXand then adds a diffpanics under debug overflow checks and wraps silently in release.
Both the
0xFE2-byte form and the 1-byte short form are reachable frombytes the peer fully controls.
Upstream does neither
io.c:2574-2578accumulates every arm into auint32, where the overflow isdefined;
io.c:2582-2586then refuses anything aboveMAX_INT32beforenarrowing:
oc had ported the sibling guard —
rsync.c'sInvalid file index: %d (%d - %d), a range check applied later against the materialised list — butnot this one. They are different guards on different quantities, and this one
runs first.
The fix
Both halves land together, because the bound alone would still leave the
i32add in place:u32(wrapping_add), matching upstream's operand types;ndx_from_unsignedthatapplies the
> i32::MAXbound.One owner rather than the bound repeated at four call sites: two sync and two
async
read_ndxbodies share these helpers, and a future fourth arm wouldotherwise be added unguarded.
protocol_violationyieldsRERR_PROTOCOL(2),matching
exit_cleanup(RERR_PROTOCOL).The
extended_fullarm is capped ati32::MAXby its own masked tag, so thebound can never fire there; it is routed through the same owner anyway
because upstream applies one check after all three arms.
How it was found, and the non-vacuity proof
modern_ndx_sequential_never_panics(proptest) hit it on an unrelated PRafter 726 successes. It is randomised, so it can surface on any PR — the
minimal input it reduced to is now pinned as a deterministic regression test:
The first
0xFE/high-bit full form seedsprev_positiveneari32::MAX;the second
0xFEadds a 16128 diff on top. The pin asserts the seed reallydoes land within one 16-bit diff of the ceiling, so the fixture cannot
silently stop discriminating.
Mutation: changing the bound to
if falsereddens the pin with— i.e. the wrapped index, which is exactly the silent-corruption outcome a
release build would have taken. The ordinary-short-diff companion stays
green, so the guard is not simply rejecting everything.
Citations
The three
io.cline references on the decode helpers were 3.4.4-era and nolonger resolved against the 3.5.0 pin (
io.c:2290issleep_for_bwlimitthere, not
read_ndx). Retargeted in the same change.Verification
protocollib: 3780 passed / 0 failedproptest_wire_format_fuzz(the suite that found it): 76 passed / 0 failedcargo fmt --all -- --check: cleancargo clippy -p protocol --all-targets --all-features: zero hits in thechanged file; the crate's residual
collapsible_if/manual_is_multiple_ofwarnings are pre-existing on master under localclippy 1.94 and are not flagged by CI's toolchain.