Skip to content

Add fallible message buffer extension helper - #715

Merged
oferchen merged 1 commit into
masterfrom
implement-rsync-3.4.1-functional-parity
Oct 20, 2025
Merged

oferchen merged 1 commit into
masterfrom
implement-rsync-3.4.1-functional-parity

Conversation

@oferchen

@oferchen oferchen commented Oct 20, 2025 •

Copy link
Copy Markdown
Owner

Summary

  • add MessageSegments::try_extend_vec so callers can handle allocation failures without mapping them into io::Error
  • reuse the new helper from extend_vec and expand the test suite to cover both success and empty cases

Testing

  • cargo test

@oferchen
oferchen merged commit 6e6c5dc into master Oct 20, 2025
@oferchen
oferchen deleted the implement-rsync-3.4.1-functional-parity branch October 20, 2025 00:23
oferchen added a commit that referenced this pull request Jun 11, 2026
The receiver-side `ensure_dest_root_exists()` pre-flight used
`symlink_metadata()` (lstat) and rejected any symlinked destination
with `InvalidInput`. Upstream `main.c:745-754` calls `do_stat()`
(follows symlinks), accepts the dest when `S_ISDIR(st.st_mode)` is
true, then enters the resolved directory via `change_dir()`. The
upstream `symlink-dirlink-basis` interop test (issue #715) drives
this path with `$HOME/dir -> $HOME/real-dir` and `-K`.

Switch the helper to `metadata()` so a symlink-to-existing-directory
dest is accepted, and surface a dangling-symlink dest as `NotFound`
via an `lstat` follow-up (instead of letting `create_dir_all`
materialize the directory at the link target). Canonicalize the
symlinked dest in `setup_transfer` so the downstream `DirSandbox`
opens the resolved target dirfd once; per-entry `*at` syscalls then
anchor at the canonical path. Skip the canonicalize step for daemon
connections so the strict `open_sandbox_for_dest_strict` path keeps
refusing symlinked dests (chdir-symlink-race defense).

Security model: per-entry writes are sandboxed by the SEC-1 `*at`
chain (`openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` on Linux
5.6+, `openat(O_NOFOLLOW | O_DIRECTORY)` elsewhere). Accepting a
symlinked dest at the pre-flight does not weaken that containment
because the canonical resolved path becomes the sandbox root.

Tests:
- Update `uts_2_dest_root_mkdir.rs` to assert the new accept-on-
  symlink-to-dir behavior and the dangling-symlink `NotFound`
  surface; remove the four pre-PR refusal tests they superseded.
- Add a chained-dangling-symlink regression and an explicit
  rejected-non-directory test.
oferchen added a commit that referenced this pull request Jun 11, 2026
The receiver-side `ensure_dest_root_exists()` pre-flight used
`symlink_metadata()` (lstat) and rejected any symlinked destination
with `InvalidInput`. Upstream `main.c:745-754` calls `do_stat()`
(follows symlinks), accepts the dest when `S_ISDIR(st.st_mode)` is
true, then enters the resolved directory via `change_dir()`. The
upstream `symlink-dirlink-basis` interop test (issue #715) drives
this path with `$HOME/dir -> $HOME/real-dir` and `-K`.

Switch the helper to `metadata()` so a symlink-to-existing-directory
dest is accepted, and surface a dangling-symlink dest as `NotFound`
via an `lstat` follow-up (instead of letting `create_dir_all`
materialize the directory at the link target). Canonicalize the
symlinked dest in `setup_transfer` so the downstream `DirSandbox`
opens the resolved target dirfd once; per-entry `*at` syscalls then
anchor at the canonical path. Skip the canonicalize step for daemon
connections so the strict `open_sandbox_for_dest_strict` path keeps
refusing symlinked dests (chdir-symlink-race defense).

Security model: per-entry writes are sandboxed by the SEC-1 `*at`
chain (`openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` on Linux
5.6+, `openat(O_NOFOLLOW | O_DIRECTORY)` elsewhere). Accepting a
symlinked dest at the pre-flight does not weaken that containment
because the canonical resolved path becomes the sandbox root.

Tests:
- Update `uts_2_dest_root_mkdir.rs` to assert the new accept-on-
  symlink-to-dir behavior and the dangling-symlink `NotFound`
  surface; remove the four pre-PR refusal tests they superseded.
- Add a chained-dangling-symlink regression and an explicit
  rejected-non-directory test.
oferchen added a commit that referenced this pull request Jun 11, 2026
The receiver-side `ensure_dest_root_exists()` pre-flight used
`symlink_metadata()` (lstat) and rejected any symlinked destination
with `InvalidInput`. Upstream `main.c:745-754` calls `do_stat()`
(follows symlinks), accepts the dest when `S_ISDIR(st.st_mode)` is
true, then enters the resolved directory via `change_dir()`. The
upstream `symlink-dirlink-basis` interop test (issue #715) drives
this path with `$HOME/dir -> $HOME/real-dir` and `-K`.

Switch the helper to `metadata()` so a symlink-to-existing-directory
dest is accepted, and surface a dangling-symlink dest as `NotFound`
via an `lstat` follow-up (instead of letting `create_dir_all`
materialize the directory at the link target). Canonicalize the
symlinked dest in `setup_transfer` so the downstream `DirSandbox`
opens the resolved target dirfd once; per-entry `*at` syscalls then
anchor at the canonical path. Skip the canonicalize step for daemon
connections so the strict `open_sandbox_for_dest_strict` path keeps
refusing symlinked dests (chdir-symlink-race defense).

Security model: per-entry writes are sandboxed by the SEC-1 `*at`
chain (`openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` on Linux
5.6+, `openat(O_NOFOLLOW | O_DIRECTORY)` elsewhere). Accepting a
symlinked dest at the pre-flight does not weaken that containment
because the canonical resolved path becomes the sandbox root.

Tests:
- Update `uts_2_dest_root_mkdir.rs` to assert the new accept-on-
  symlink-to-dir behavior and the dangling-symlink `NotFound`
  surface; remove the four pre-PR refusal tests they superseded.
- Add a chained-dangling-symlink regression and an explicit
  rejected-non-directory test.
oferchen added a commit that referenced this pull request Jun 11, 2026
)

* fix(receiver): follow symlink at dest_root to match upstream

The receiver-side `ensure_dest_root_exists()` pre-flight used
`symlink_metadata()` (lstat) and rejected any symlinked destination
with `InvalidInput`. Upstream `main.c:745-754` calls `do_stat()`
(follows symlinks), accepts the dest when `S_ISDIR(st.st_mode)` is
true, then enters the resolved directory via `change_dir()`. The
upstream `symlink-dirlink-basis` interop test (issue #715) drives
this path with `$HOME/dir -> $HOME/real-dir` and `-K`.

Switch the helper to `metadata()` so a symlink-to-existing-directory
dest is accepted, and surface a dangling-symlink dest as `NotFound`
via an `lstat` follow-up (instead of letting `create_dir_all`
materialize the directory at the link target). Canonicalize the
symlinked dest in `setup_transfer` so the downstream `DirSandbox`
opens the resolved target dirfd once; per-entry `*at` syscalls then
anchor at the canonical path. Skip the canonicalize step for daemon
connections so the strict `open_sandbox_for_dest_strict` path keeps
refusing symlinked dests (chdir-symlink-race defense).

Security model: per-entry writes are sandboxed by the SEC-1 `*at`
chain (`openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` on Linux
5.6+, `openat(O_NOFOLLOW | O_DIRECTORY)` elsewhere). Accepting a
symlinked dest at the pre-flight does not weaken that containment
because the canonical resolved path becomes the sandbox root.

Tests:
- Update `uts_2_dest_root_mkdir.rs` to assert the new accept-on-
  symlink-to-dir behavior and the dangling-symlink `NotFound`
  surface; remove the four pre-PR refusal tests they superseded.
- Add a chained-dangling-symlink regression and an explicit
  rejected-non-directory test.

* style: apply cargo fmt to receiver dest_root + test wrappings
oferchen added a commit that referenced this pull request Jun 17, 2026
The server-side compact flag parser silently dropped the 'K' byte the
client emits whenever `--keep-dirlinks` is active. With the flag absent
from `ParsedServerFlags`, the receiver constructed `MetadataOptions`
with `keep_dirlinks: false`, so the dirfd-anchored chmod bypass added
in PR #5793 never engaged: every per-file chmod through a destination
dir-symlink (`$HOME/dir/file` when `dir -> real-dir`) was refused with
ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario
in `testsuite/symlink-dirlink-basis.test` (Issue #715, eight topologies
covering basic / nested / --backup / --inplace / top-level / proto-28
/ --partial-dir) bottoms out on this same gap.

Wire `K` and `k` into the compact flag parser and propagate the parsed
`keep_dirlinks` into the receiver's `MetadataOptions` via
`with_keep_dirlinks`, matching upstream `generator.c:1344`'s
`link_stat(fname, &sx.st, keep_dirlinks && is_dir)`.

upstream: options.c:688 / generator.c:1344
oferchen added a commit that referenced this pull request Jun 17, 2026
The server-side compact flag parser silently dropped the 'K' byte the
client emits whenever `--keep-dirlinks` is active. With the flag absent
from `ParsedServerFlags`, the receiver constructed `MetadataOptions`
with `keep_dirlinks: false`, so the dirfd-anchored chmod bypass added
in PR #5793 never engaged: every per-file chmod through a destination
dir-symlink (`$HOME/dir/file` when `dir -> real-dir`) was refused with
ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario
in `testsuite/symlink-dirlink-basis.test` (Issue #715, eight topologies
covering basic / nested / --backup / --inplace / top-level / proto-28
/ --partial-dir) bottoms out on this same gap.

Wire `K` and `k` into the compact flag parser and propagate the parsed
`keep_dirlinks` into the receiver's `MetadataOptions` via
`with_keep_dirlinks`, matching upstream `generator.c:1344`'s
`link_stat(fname, &sx.st, keep_dirlinks && is_dir)`.

upstream: options.c:688 / generator.c:1344
oferchen added a commit that referenced this pull request Jun 17, 2026
The server-side compact flag parser silently dropped the 'K' byte the
client emits whenever `--keep-dirlinks` is active. With the flag absent
from `ParsedServerFlags`, the receiver constructed `MetadataOptions`
with `keep_dirlinks: false`, so the dirfd-anchored chmod bypass added
in PR #5793 never engaged: every per-file chmod through a destination
dir-symlink (`$HOME/dir/file` when `dir -> real-dir`) was refused with
ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario
in `testsuite/symlink-dirlink-basis.test` (Issue #715, eight topologies
covering basic / nested / --backup / --inplace / top-level / proto-28
/ --partial-dir) bottoms out on this same gap.

Wire `K` and `k` into the compact flag parser and propagate the parsed
`keep_dirlinks` into the receiver's `MetadataOptions` via
`with_keep_dirlinks`, matching upstream `generator.c:1344`'s
`link_stat(fname, &sx.st, keep_dirlinks && is_dir)`.

upstream: options.c:688 / generator.c:1344
oferchen added a commit that referenced this pull request Jun 17, 2026
The server-side compact flag parser silently dropped the 'K' byte the
client emits whenever `--keep-dirlinks` is active. With the flag absent
from `ParsedServerFlags`, the receiver constructed `MetadataOptions`
with `keep_dirlinks: false`, so the dirfd-anchored chmod bypass added
in PR #5793 never engaged: every per-file chmod through a destination
dir-symlink (`$HOME/dir/file` when `dir -> real-dir`) was refused with
ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario
in `testsuite/symlink-dirlink-basis.test` (Issue #715, eight topologies
covering basic / nested / --backup / --inplace / top-level / proto-28
/ --partial-dir) bottoms out on this same gap.

Wire `K` and `k` into the compact flag parser and propagate the parsed
`keep_dirlinks` into the receiver's `MetadataOptions` via
`with_keep_dirlinks`, matching upstream `generator.c:1344`'s
`link_stat(fname, &sx.st, keep_dirlinks && is_dir)`.

upstream: options.c:688 / generator.c:1344
oferchen added a commit that referenced this pull request Jun 17, 2026
…#5853)

The server-side compact flag parser silently dropped the 'K' byte the
client emits whenever `--keep-dirlinks` is active. With the flag absent
from `ParsedServerFlags`, the receiver constructed `MetadataOptions`
with `keep_dirlinks: false`, so the dirfd-anchored chmod bypass added
in PR #5793 never engaged: every per-file chmod through a destination
dir-symlink (`$HOME/dir/file` when `dir -> real-dir`) was refused with
ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario
in `testsuite/symlink-dirlink-basis.test` (Issue #715, eight topologies
covering basic / nested / --backup / --inplace / top-level / proto-28
/ --partial-dir) bottoms out on this same gap.

Wire `K` and `k` into the compact flag parser and propagate the parsed
`keep_dirlinks` into the receiver's `MetadataOptions` via
`with_keep_dirlinks`, matching upstream `generator.c:1344`'s
`link_stat(fname, &sx.st, keep_dirlinks && is_dir)`.

upstream: options.c:688 / generator.c:1344
oferchen added a commit that referenced this pull request Jun 17, 2026
Pins the receiver-side wiring that the upstream rsync 3.4.4 testsuite
`symlink-dirlink-basis` test exercises against -K/--keep-dirlinks. The
chmod dirfd-sandbox bypass (#5793) plus the compact `K` flag parser
wire-up (#5853) close the failure; this test file is the regression
coverage for both halves together.

Each test mirrors one of the eight Test N scenarios in
`testsuite/symlink-dirlink-basis.test` (Issue #715): basic, compressed,
nested, --backup, --inplace, top-level (negative control), proto28
--partial-dir, and proto28 basic. The negative control catches a
parser regression that would silently set keep_dirlinks for the
non-symlinked top-level case.

Pins both halves of the chain:
- ParsedServerFlags::parse recognises the compact `K` byte from the
  server-side flag string the client emits in every topology.
- The parsed flag survives MetadataOptions::with_keep_dirlinks, which
  is what chmod_path_honoring_keep_dirlinks consults at apply time.

Upstream sources of truth:
- target/interop/upstream-src/rsync-3.4.4/testsuite/symlink-dirlink-basis.test
- target/interop/upstream-src/rsync-3.4.1/options.c:688 (-K mapping)
- target/interop/upstream-src/rsync-3.4.1/generator.c:1344
  (link_stat(fname, &sx.st, keep_dirlinks && is_dir))
oferchen added a commit that referenced this pull request Jun 17, 2026
Pins the receiver-side wiring that the upstream rsync 3.4.4 testsuite
`symlink-dirlink-basis` test exercises against -K/--keep-dirlinks. The
chmod dirfd-sandbox bypass (#5793) plus the compact `K` flag parser
wire-up (#5853) close the failure; this test file is the regression
coverage for both halves together.

Each test mirrors one of the eight Test N scenarios in
`testsuite/symlink-dirlink-basis.test` (Issue #715): basic, compressed,
nested, --backup, --inplace, top-level (negative control), proto28
--partial-dir, and proto28 basic. The negative control catches a
parser regression that would silently set keep_dirlinks for the
non-symlinked top-level case.

Pins both halves of the chain:
- ParsedServerFlags::parse recognises the compact `K` byte from the
  server-side flag string the client emits in every topology.
- The parsed flag survives MetadataOptions::with_keep_dirlinks, which
  is what chmod_path_honoring_keep_dirlinks consults at apply time.

Upstream sources of truth:
- target/interop/upstream-src/rsync-3.4.4/testsuite/symlink-dirlink-basis.test
- target/interop/upstream-src/rsync-3.4.1/options.c:688 (-K mapping)
- target/interop/upstream-src/rsync-3.4.1/generator.c:1344
  (link_stat(fname, &sx.st, keep_dirlinks && is_dir))
oferchen added a commit that referenced this pull request Jun 17, 2026
… (#5871)

Pins the receiver-side wiring that the upstream rsync 3.4.4 testsuite
`symlink-dirlink-basis` test exercises against -K/--keep-dirlinks. The
chmod dirfd-sandbox bypass (#5793) plus the compact `K` flag parser
wire-up (#5853) close the failure; this test file is the regression
coverage for both halves together.

Each test mirrors one of the eight Test N scenarios in
`testsuite/symlink-dirlink-basis.test` (Issue #715): basic, compressed,
nested, --backup, --inplace, top-level (negative control), proto28
--partial-dir, and proto28 basic. The negative control catches a
parser regression that would silently set keep_dirlinks for the
non-symlinked top-level case.

Pins both halves of the chain:
- ParsedServerFlags::parse recognises the compact `K` byte from the
  server-side flag string the client emits in every topology.
- The parsed flag survives MetadataOptions::with_keep_dirlinks, which
  is what chmod_path_honoring_keep_dirlinks consults at apply time.

Upstream sources of truth:
- target/interop/upstream-src/rsync-3.4.4/testsuite/symlink-dirlink-basis.test
- target/interop/upstream-src/rsync-3.4.1/options.c:688 (-K mapping)
- target/interop/upstream-src/rsync-3.4.1/generator.c:1344
  (link_stat(fname, &sx.st, keep_dirlinks && is_dir))
oferchen added a commit that referenced this pull request Aug 24, 2026
)

* fix(receiver): follow symlink at dest_root to match upstream

The receiver-side `ensure_dest_root_exists()` pre-flight used
`symlink_metadata()` (lstat) and rejected any symlinked destination
with `InvalidInput`. Upstream `main.c:745-754` calls `do_stat()`
(follows symlinks), accepts the dest when `S_ISDIR(st.st_mode)` is
true, then enters the resolved directory via `change_dir()`. The
upstream `symlink-dirlink-basis` interop test (issue #715) drives
this path with `$HOME/dir -> $HOME/real-dir` and `-K`.

Switch the helper to `metadata()` so a symlink-to-existing-directory
dest is accepted, and surface a dangling-symlink dest as `NotFound`
via an `lstat` follow-up (instead of letting `create_dir_all`
materialize the directory at the link target). Canonicalize the
symlinked dest in `setup_transfer` so the downstream `DirSandbox`
opens the resolved target dirfd once; per-entry `*at` syscalls then
anchor at the canonical path. Skip the canonicalize step for daemon
connections so the strict `open_sandbox_for_dest_strict` path keeps
refusing symlinked dests (chdir-symlink-race defense).

Security model: per-entry writes are sandboxed by the SEC-1 `*at`
chain (`openat2(RESOLVE_BENEATH | RESOLVE_NO_SYMLINKS)` on Linux
5.6+, `openat(O_NOFOLLOW | O_DIRECTORY)` elsewhere). Accepting a
symlinked dest at the pre-flight does not weaken that containment
because the canonical resolved path becomes the sandbox root.

Tests:
- Update `uts_2_dest_root_mkdir.rs` to assert the new accept-on-
  symlink-to-dir behavior and the dangling-symlink `NotFound`
  surface; remove the four pre-PR refusal tests they superseded.
- Add a chained-dangling-symlink regression and an explicit
  rejected-non-directory test.

* style: apply cargo fmt to receiver dest_root + test wrappings
oferchen added a commit that referenced this pull request Aug 24, 2026
…#5853)

The server-side compact flag parser silently dropped the 'K' byte the
client emits whenever `--keep-dirlinks` is active. With the flag absent
from `ParsedServerFlags`, the receiver constructed `MetadataOptions`
with `keep_dirlinks: false`, so the dirfd-anchored chmod bypass added
in PR #5793 never engaged: every per-file chmod through a destination
dir-symlink (`$HOME/dir/file` when `dir -> real-dir`) was refused with
ELOOP/ENOTDIR before any delta could land. Every basis-symlink scenario
in `testsuite/symlink-dirlink-basis.test` (Issue #715, eight topologies
covering basic / nested / --backup / --inplace / top-level / proto-28
/ --partial-dir) bottoms out on this same gap.

Wire `K` and `k` into the compact flag parser and propagate the parsed
`keep_dirlinks` into the receiver's `MetadataOptions` via
`with_keep_dirlinks`, matching upstream `generator.c:1344`'s
`link_stat(fname, &sx.st, keep_dirlinks && is_dir)`.

upstream: options.c:688 / generator.c:1344
oferchen added a commit that referenced this pull request Aug 24, 2026
… (#5871)

Pins the receiver-side wiring that the upstream rsync 3.4.4 testsuite
`symlink-dirlink-basis` test exercises against -K/--keep-dirlinks. The
chmod dirfd-sandbox bypass (#5793) plus the compact `K` flag parser
wire-up (#5853) close the failure; this test file is the regression
coverage for both halves together.

Each test mirrors one of the eight Test N scenarios in
`testsuite/symlink-dirlink-basis.test` (Issue #715): basic, compressed,
nested, --backup, --inplace, top-level (negative control), proto28
--partial-dir, and proto28 basic. The negative control catches a
parser regression that would silently set keep_dirlinks for the
non-symlinked top-level case.

Pins both halves of the chain:
- ParsedServerFlags::parse recognises the compact `K` byte from the
  server-side flag string the client emits in every topology.
- The parsed flag survives MetadataOptions::with_keep_dirlinks, which
  is what chmod_path_honoring_keep_dirlinks consults at apply time.

Upstream sources of truth:
- target/interop/upstream-src/rsync-3.4.4/testsuite/symlink-dirlink-basis.test
- target/interop/upstream-src/rsync-3.4.1/options.c:688 (-K mapping)
- target/interop/upstream-src/rsync-3.4.1/generator.c:1344
  (link_stat(fname, &sx.st, keep_dirlinks && is_dir))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant