Skip to content

fix(transfer): refuse an ITEM_TRANSFER request for a non-regular file per rsync.c:436-444 - #7744

Merged
oferchen merged 1 commit into
masterfrom
fix/transfer-non-regular-item-transfer-guard
Sep 8, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/transfer-non-regular-item-transfer-guard

Conversation

@oferchen

@oferchen oferchen commented Sep 7, 2026

Copy link
Copy Markdown
Owner

What

Upstream refuses an ITEM_TRANSFER frame that does not name a regular file, on BOTH ends that read a request/echo: rsync.c:436-444 — if (iflags & ITEM_TRANSFER) with i < 0 || !S_ISREG(cur_flist->files[i]->mode) prints received request to transfer non-regular file: %d [%s] (:439-441) and exits RERR_PROTOCOL (:442). oc had NO read-side analogue: the only look-alike was the REQUESTING side's polite is_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:

  • ONE diagnostic owner: 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.
  • Receiver side: the predicate lives inside read_ndx_and_attrs via a new non-defaulted FlistMarkerSink::ndx_is_regular_file (mirroring ndx_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.
  • Sender side: a 9-line guard at its own attrs read, calling the shared diagnostic.

The :913 requester-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 < 0 residual is the INC_RECURSE gap NDX, which oc's resolve_itemize_ndx maps to the owning DIRECTORY, so the S_ISREG half refuses it exactly where upstream refuses i < 0. Past-end indexes stay with validate_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_ACTIVE check (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:264 and three pipeline.rs echo drains read via SenderAttrs::read_with_codec_xattr, bypassing the primitive — outside the two sites this change targets (flagged; sync.rs's run_sync is 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 warnings clean, nextest -p transfer --lib 2494/2494.

… 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.
@oferchen
oferchen enabled auto-merge (squash) September 7, 2026 23:14
@github-actions github-actions Bot added the bug Something isn't working label Sep 8, 2026
@oferchen
oferchen merged commit 002acb1 into master Sep 8, 2026
76 checks passed
@oferchen
oferchen deleted the fix/transfer-non-regular-item-transfer-guard branch September 8, 2026 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant