Skip to content

fix: convert a forwarded --files-from list only under -s - #8874

Merged
oferchen merged 2 commits into
masterfrom
fix/files-from-iconv-protect-args
Nov 27, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/files-from-iconv-protect-args

Conversation

@oferchen

Copy link
Copy Markdown
Owner

What rsync 3.5.2 does

A --files-from list carried over the connection is converted with --iconv only under --protect-args / --secluded-args:

  • compat.c:820-827 - if (protect_args && files_from) sets filesfrom_convert: filesfrom_host && ic_send != -1 on the sender, !filesfrom_host && ic_recv != -1 on the receiver.
  • io.c:502 - forward_filesfrom_data() converts each forwarded name with ic_send only under filesfrom_convert.
  • flist.c:2766 - send_file_list() adds RL_CONVERT to its read_line() flags only under filesfrom_convert.
  • io.c:505 and io.c:1462 - both conversions use ICB_INCLUDE_BAD, which converts what it can and copies each unconvertible byte through verbatim (rsync.c:262).

A server learns protect_args from the client's -s (main.c:1960-1962 over a remote shell, clientserver.c:1165-1167 on a daemon).

What oc did

  • A sender reading a forwarded list (--files-from=-) converted it whenever --iconv was set, with or without -s. Against a 3.5.2 client pulling without -s, oc copied a file 3.5.2 reports missing.
  • A server receiver forwarding a list it opened (--files-from=:list on a push) never converted it, even under -s, so a 3.5.2 client pushing with -s missed its file.
  • Both directions converted strictly: one invalid byte made the whole name fall back to its raw bytes, so the valid characters around it were left unconverted.

The fix

  • ConnectionConfig gains protect_args, set by the remote-shell server from its -s detection, by the daemon from the client's option args, and by the client from its resolved --protect-args.
  • ConnectionConfig::files_from_converter() returns the --iconv converter only under protect_args. Both the reading sender and the forwarding server receiver use it.
  • forward_files_from and read_files_from_stream use the ICB_INCLUDE_BAD converters (local_to_remote_lossy / remote_to_local_lossy), which already exist for read_line(RL_CONVERT) and secluded args.

The implied-include code is not touched.

Measured (host, glibc)

Client --iconv=UTF-8,ISO-8859-1 over a remote shell. latin1 is café: UTF-8 on the client, ISO-8859-1 on the server. bad is bad\xff. A local list is in the client's charset, a remote (:list) list in the server's. Each cell shows the exit code and what reached the destination.

cell 3.5.2 to 3.5.2 3.5.2 client, oc server (before) 3.5.2 client, oc server (after) oc to oc (before) oc to oc (after)
pull local, no -s, latin1 23, none 0, café 23, none 0, café 23, none
pull local, no -s, bad 4, none 4, none 4, none 4, none 4, none
pull local, -s, latin1 0, café 0, café 0, café 0, café 0, café
pull local, -s, bad 4, none 4, none 4, none 4, none 4, none
pull remote, no -s / -s, latin1 0, café 0, café 0, café 0, café 0, café
pull remote, no -s / -s, bad 0, badÿ 0, badÿ 0, badÿ 0, badÿ 0, badÿ
push local, no -s / -s, latin1 0, caf\351 0, caf\351 0, caf\351 0, caf\351 0, caf\351
push local, no -s / -s, bad 23, none 23, none 23, none 23, none 23, none
push remote, no -s, latin1 23, none 23, none 23, none 23, none 23, none
push remote, no -s, bad 23, none 23, none 23, none 23, none 23, none
push remote, -s, latin1 0, caf\351 23, none 0, caf\351 23, none 0, caf\351
push remote, -s, bad 23, none 23, none 23, none 23, none 23, none

After the fix, all 16 cells of the 3.5.2-client, oc-server pairing match 3.5.2 exactly, and so do the oc-to-oc exit codes and destinations. Both binaries were built from this branch and its base in a target dir used by this branch alone.

The exit-4 bad pull cells are the receiver rejecting the converted name as unrequested. 3.5.2 does the same, and that path is the implied-include check, which this change leaves alone.

Tests

  • crates/cli/tests/files_from_iconv_protect_args.rs (new, 8 cells): pull, push from a remote list, daemon pull with charset = ISO-8859-1, and a push from an ISO-8859-1 client, each with and without -s. The expected values are the 3.5.2 results. With OC_RSYNC_UPSTREAM_COMPAT=1 each cell also runs 3.5.2 at both ends and with one end each.
  • generator::tests::files_from - a stream name is looked up unconverted without protect_args and converted with it.
  • receiver files_from_forwarding_framing_tests - a server receiver forwards unconverted without protect_args and converted with it.
  • protocol::files_from - a name holding one invalid byte has its valid characters converted and the bad byte copied, on both the forward and the read side.

Mutation results (each fix site reverted on its own; each revert fails at least one new test):

reverted failing tests
sender gate (filters.rs) generator unit test; cli pull and daemon pull without -s
receiver forward (context.rs) receiver unit test; cli push with -s
ICB_INCLUDE_BAD conversion (files_from.rs) both protocol invalid-byte tests
remote-shell server -s wiring (run.rs) cli pull and push with -s
daemon -s wiring (server_config.rs) cli daemon pull with -s
client protect_args wiring (flags.rs) cli ISO-8859-1 client push with -s

Remaining differences (not fixed here)

  • oc client with -s pulling from a 3.5.2 daemon reads the list unconverted and exits 23, where 3.5.2 at both ends exits 0. The behaviour is the same before this change. The oc client sends --secluded-args --iconv=ISO-8859-1 in the first pass, while 3.5.2 sends -s inside its flag string and --iconv=UTF-8 (its client truncates iconv_opt in setup_iconv(), rsync.c:119-123, before server_options() runs). The test leaves out that one pairing and says so in a comment.
  • Diagnostics with a non-UTF-8 name: the oc sender's link_stat line shows caf\357\277\275 where 3.5.2 prints caf\#351. The lookup used the raw bytes, and the exit code and result match. Only the message text is lossy, because sender diagnostics are built as Rust Strings.
  • Push of an invalid UTF-8 local name (bad\xff): exit 23 matches, but oc reports [receiver] cannot convert filename plus extra delete_file/could not make way lines, where 3.5.2 reports [sender] cannot convert filename. That is flist iconv, not files-from.

Closes #8864

rsync 3.5.2 converts a --files-from list carried over the connection
only when protect_args is set: compat.c:820-827 gates filesfrom_convert
on protect_args && files_from, and io.c:502 (forwarding) and
flist.c:2766 (reading) consult it. An oc sender converted the list
whenever --iconv was set, so a 3.5.2 client pulling without -s got a
file 3.5.2 reports missing. An oc server receiver never converted a
list it opened, so a 3.5.2 client pushing with --files-from=:list and
-s missed its file.

ConnectionConfig now carries protect_args, set from the server's -s
(main.c:1960-1962), the daemon client's option args
(clientserver.c:1165-1167) and the client's own option, and
files_from_converter() yields the converter only under it.

Both directions now use the ICB_INCLUDE_BAD converters (io.c:505,
io.c:1462): valid characters are converted and each bad byte is copied
through (rsync.c:262), where the strict path kept the whole name raw.
@oferchen oferchen added this to the v0.6.5 milestone Nov 27, 2026
@github-actions github-actions Bot added the bug Something isn't working label Nov 27, 2026
APFS and HFS+ refuse a name that is not valid UTF-8 (EILSEQ), so the
ISO-8859-1 fixture cannot be created there and every cell panicked on
macOS before reaching the transfer. Also wrap a line rustfmt splits.
@oferchen
oferchen merged commit d12d346 into master Nov 27, 2026
89 checks passed
@oferchen
oferchen deleted the fix/files-from-iconv-protect-args branch November 27, 2026 06: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.

Server converts a forwarded --files-from list with --iconv even without -s; invalid bytes become U+FFFD

1 participant