Repository navigation
fix(transfer): refuse an ITEM_TRANSFER request for a non-regular file per rsync.c:436-444 - #7744
Merged
Merged
Conversation
… per rsync.c:436-444
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.
What
Upstream refuses an
ITEM_TRANSFERframe that does not name a regular file, on BOTH ends that read a request/echo: rsync.c:436-444 —if (iflags & ITEM_TRANSFER)withi < 0 || !S_ISREG(cur_flist->files[i]->mode)printsreceived request to transfer non-regular file: %d [%s](:439-441) and exitsRERR_PROTOCOL(:442). oc had NO read-side analogue: the only look-alike was the REQUESTING side's politeis_file()skip in the generator, which cannot defend against a peer's frame, and the ndx_stream module doc claimed the guard "stays with its current owner" while no read-side owner existed (and cited drifted lines :420-428). Severity was capped by open-time defences (O_NOFOLLOW + post-open fstat/IS_DEVICE), so this is defence-in-depth plus diagnostic parity — the guard now refuses at protocol time, where upstream does.Placement
Hybrid single-owner. The sender's request read never routes through the shared NDX primitive (it open-codes NDX+iflags in
run_transfer_loop), so a purely in-primitive guard could cover only one of the two sites without a wide signature refactor. Instead:ndx_stream::non_regular_transfer_request(ndx, role)— upstream wording + oc's location/role-trailer convention, protocol-violation-tagged so the exit-code mapper yields RERR_PROTOCOL (2), same as sibling gates.read_ndx_and_attrsvia a new non-defaultedFlistMarkerSink::ndx_is_regular_file(mirroringndx_is_active, so a future sink cannot silently carry the guard past a list it owns). Resolution reuses the existing resolvers only (wire_to_flat_ndx/NdxMap) — no third NDX->entry resolver.The
:913requester-side skip is untouched (now unreachable for ITEM_TRANSFER frames, matching upstream where send_files never sees such a frame). The module doc's misleading line and the drifted citation are fixed in the same commit.Overlap with existing gates, stated precisely
#7365 (negative NDX) and #7630 (overflow) fire BEFORE upstream's guard would — zero overlap. Upstream's
i < 0residual is the INC_RECURSE gap NDX, which oc'sresolve_itemize_ndxmaps to the owning DIRECTORY, so the S_ISREG half refuses it exactly where upstream refusesi < 0. Past-end indexes stay withvalidate_file_index/ the echo-ordering check; this guard never claims range faults — a sink that cannot resolve an entry reports regular and defers to the owners of range faults rather than mislabeling them with the non-regular diagnostic. The NEW substance is the S_ISREG check on both sites.One behavioural ordering fix
An ITEM_TRANSFER frame naming a CLEARED slot is now refused by this guard (a zeroed mode fails S_ISREG) — faithful to upstream, where :436-444 runs before recv_files'
F_IS_ACTIVEcheck (receiver.c:871-881). The existing cleared-entry test moved to a non-transfer frame (which the cleared diagnostic genuinely owns) and a new test pins the ordering.Tests + mutations (measured)
Nine new tests across the primitive, the receiver wiring witness, and the sender site — each refusal test paired with a regular-entry non-vacuity companion. Mutation A (primitive guard disabled): exactly the 3 primitive-site refusal tests fail, 16 siblings green. Mutation B (sender guard disabled): exactly the 2 sender refusal tests fail, 17 green. Both reverted.
Scoped out
receiver/transfer/sync.rs:264and threepipeline.rsecho drains read viaSenderAttrs::read_with_codec_xattr, bypassing the primitive — outside the two sites this change targets (flagged; sync.rs'srun_syncis the known-unreachable staged path). oc deliberately keeps reclaimed INC_RECURSE segments indexable (NdxMap totality), so upstream's freed-flist abort for a stale-but-in-range index has no direct analogue here.Gates
Pinned 1.88.0: whole-tree rustfmt clean (3426 files),
clippy -p transfer --all-targets -D warningsclean,nextest -p transfer --lib2494/2494.