Repository navigation
fix(sender): reject stray negative NDX instead of skipping it - #7365
Merged
Merged
Conversation
upstream: rsync.c:343-353. Inside `read_ndx_and_attrs`'s read_loop the gate
`if (!inc_recurse || am_sender)` sits ABOVE both the NDX_FLIST_EOF branch
(:354) and the sub-list branch (:360), so for a sender every remaining
negative index is rejected with
Invalid file index: %d (%d - %d) [%s]
followed by exit_cleanup(RERR_PROTOCOL). Only a receiver inside the
INC_RECURSE window may grow its file list from the stream.
oc's send loop open-coded the classifier and skipped three of those cases:
NDX_FLIST_EOF, any `ndx <= NDX_FLIST_OFFSET`, and any other negative value
each logged at debug level and continued. A peer could desync the loop with
no diagnostic and no exit code. The three collapse into one arm because
upstream rejects them at one site.
The rejection reuses `ndx_stream::invalid_file_index`, which already renders
upstream's wording and is tagged as a protocol violation, so the message has
a single owner. NDX_DEL_STATS keeps its own arm: upstream drains it at :337,
above the gate.
The whole suite passed before and after, which is how the divergence
survived - nothing exercised it. The three new tests fail when the
fail-open `continue` is restored; the fourth is the non-vacuity companion
and passes either way, guarding against the fix turning a legitimate
NDX_DEL_STATS frame into a fatal.
transfer: 2753 run, 2753 passed.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
upstream: rsync.c:343-353. Inside `read_ndx_and_attrs`'s read_loop the gate
`if (!inc_recurse || am_sender)` sits ABOVE both the NDX_FLIST_EOF branch
(:354) and the sub-list branch (:360), so for a sender every remaining
negative index is rejected with
Invalid file index: %d (%d - %d) [%s]
followed by exit_cleanup(RERR_PROTOCOL). Only a receiver inside the
INC_RECURSE window may grow its file list from the stream.
oc's send loop open-coded the classifier and skipped three of those cases:
NDX_FLIST_EOF, any `ndx <= NDX_FLIST_OFFSET`, and any other negative value
each logged at debug level and continued. A peer could desync the loop with
no diagnostic and no exit code. The three collapse into one arm because
upstream rejects them at one site.
The rejection reuses `ndx_stream::invalid_file_index`, which already renders
upstream's wording and is tagged as a protocol violation, so the message has
a single owner. NDX_DEL_STATS keeps its own arm: upstream drains it at :337,
above the gate.
The whole suite passed before and after, which is how the divergence
survived - nothing exercised it. The three new tests fail when the
fail-open `continue` is restored; the fourth is the non-vacuity companion
and passes either way, guarding against the fix turning a legitimate
NDX_DEL_STATS frame into a fatal.
transfer: 2753 run, 2753 passed.
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.
Upstream
read_ndx_and_attrs's read_loop (rsync.c:329-381) handles negative indices in a fixed order:The gate is above the
NDX_FLIST_EOFand sub-list branches. For a sender (am_sender) it is unconditional — those are not markers to skip, they are protocol violations. Only a receiver inside the INC_RECURSE window may grow its file list from the stream.The defect
run_transfer_loopis oc'ssend_filesanalogue (its own comments citesender.c:256-261/:267-272, and upstream reads its NDX via the sameread_ndx_and_attrsatsender.c:236). It open-coded the classifier and failed open on three arms:NDX_FLIST_EOFdebug_log!+continue_ if ndx <= NDX_FLIST_OFFSETdebug_log!+continue_(unknown negative)debug_log!+continueA peer could desync the send loop with no diagnostic and no exit code.
Change
The three arms collapse into one, because upstream rejects them at one site. The error comes from
ndx_stream::invalid_file_index, which already renders upstream's exact wording and is tagged as a protocol violation →RERR_PROTOCOL(2), so the message keeps a single owner rather than gaining a second copy.lastmirrorsGoodbyeNdxSink::last_file_ndx(rsync.c:345-348).NDX_DEL_STATSdeliberately keeps its own arm — upstream drains it at:337, above the gate — as doesNDX_DONE, which carries oc's phase-transition logic.This is not a behaviour-neutral refactor: it converts three silent-continue arms into hard exits. That is the point.
Why it survived
The full suite passed before and after the fix — nothing exercised these arms. That is the signature of a silent fail-open, and it is why the tests below assert the new behaviour directly rather than relying on the suite.
Verification
continueahead of the rejection makes all three fail.sender_still_accepts_del_stats_then_done: feeds a realNDX_DEL_STATSframe plus its five varints and asserts the loop still completes. It passes both before and after — it exists to catch a fix that turns a legitimate frame fatal.cargo nextest run -p transfer --all-features: 2753 run, 2753 passedcargo fmt --all -- --check: cleancargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warnings: cleanContext
This is the fourth and last open copy of the NDX classifier. The other three (
read_next_frame,read_ndx_skipping_del_stats, the goodbye loop) were already collapsed onto the sharedndx_streamprimitive by #7228 — this one was missed, and it is the only one that ever had a contract divergence rather than being a pure duplicate.