Repository navigation
Add documentation outlining current parity gaps - #303
Merged
Merged
Conversation
oferchen
added a commit
that referenced
this pull request
Nov 17, 2026
## Summary Under a UTF-8 locale a client printed every non-ASCII file name escaped (`caf\#303\#251`) where rsync 3.5.2 prints `café`. - A client without `-8` now checks terminal output against the locale codeset, as upstream does with `ic_chck` (rsync.c:95-98, log.c:462-499): valid printable characters print raw; invalid bytes, C0 controls other than tab, DEL and C1 controls are escaped; a literal `\#ddd` keeps its guard. - The codeset comes from `setlocale(LC_CTYPE, "")` and `nl_langinfo(CODESET)` (main.c:1911), through a new `platform::locale`, set before any thread starts. It replaces a guess from the text of `LANG`/`LC_*`. - Server and daemon output, `-8` and log files are unchanged. - `EscapeStyle` docs and citations now describe 3.5.2's `filtered_fwrite`; the redundant `escape_c1` field is removed with no behaviour change. ## Tests - `crates/cli/tests/client_output_locale_escaping.rs`: seven cells compare stdout byte for byte with the rsync 3.5.2 binary (`--list-only`, `-rv`, `-ri` under `C.UTF-8` and `C`, plus `-rv8`). Before the fix the three UTF-8 cells fail; the `C` and `-8` cells pass either way and act as controls. The test fails, not skips, in CI when the oracle is missing. - Eleven unit tests in `logging/src/escape.rs`; two fail when the codeset check is forced off. ## Known gaps - Codesets other than ASCII and UTF-8 (ISO-8859-x, GBK, EUC-JP) keep the conservative escaping, since they cannot be validated without iconv; upstream prints a printable Latin-1 byte raw. A unit test pins this. - Windows keeps the conservative escaping. - The server path is covered by a unit test, not an end-to-end cell.
oferchen
added a commit
that referenced
this pull request
Nov 27, 2026
## What rsync 3.5.2 does Under `-s`, `server_options()` builds `--server`, `--sender` (on a pull), the compact flag string with `s` as its first letter (options.c:2858-2859) and `--iconv=...` (options.c:2975-2983), then inserts a `NULL` (options.c:2985-2986). `start_inband_exchange()` sends the args before that `NULL` in the first pass (clientserver.c:443-450). `send_protected_args()` then sends `rsync` and only the args after the `NULL` (rsync.c:284-296). A daemon client runs `setup_iconv()` before `server_options()` (clientserver.c:171-172 for a socket, main.c:678-679 before `start_inband_exchange()` over a remote shell). `rsync.c:119-123` truncates `iconv_opt` at the comma there, so the daemon is sent the local charset. A remote-shell server is different: `main.c:624` runs `server_options()` before `setup_iconv()`, so it gets the post-comma half. oc already sends that correctly. ## Why the 3.5.2 daemon read the list unconverted I captured the daemon's stdin with strace (`--iconv=UTF-8,ISO-8859-1 -s --files-from=list`, module `charset = ISO-8859-1`): ``` 3.5.2 client: --server\0--sender\0-srRe.iLsfxCIvu\0--iconv=UTF-8\0\0 rsync\0--files-from=-\0--from0\0.\0src/\0\0 oc client: --server\0--sender\0--secluded-args\0--iconv=ISO-8859-1\0\0 rsync\0--server\0--sender\0-rRe.iLsfxCIvu\0--files-from=-\0--from0\0.\0src/\0\0 ``` oc's second pass repeated `--server`. The daemon's second `parse_arguments()` handles `OPT_SERVER` and sets `iconv_opt = NULL` (options.c:1535-1547). `rsync_module()` then sees no `iconv_opt` and closes the `ic_send`/`ic_recv` converters that came from the module `charset` (clientserver.c:1279-1289). With no converters, `filesfrom_convert` stays 0 (compat.c:820-826). The daemon sender looked up the raw UTF-8 name and failed with `link_stat "caf\#303\#251" (in src) failed`, which gives exit 23. The `--iconv` value itself does not matter on the daemon, because its converters come only from the module `charset` (clientserver.c:763-768). Only the repeated `--server` breaks the transfer. ## The fix Daemon client argv only (`orchestration/arguments.rs`): - The flag string carries `s` under `-s`, and `--iconv=` follows it directly, as in upstream. - The first pass is the upstream prefix: `--server`, `--sender` on a pull, the flag string and `--iconv`. The protected args are `rsync` plus everything after it. Nothing from the first pass is repeated. - `--iconv=` forwards the local charset (the pre-comma half). - `--checksum-choice` moves from before the flag string to after `--suffix`, its upstream position (options.c:3052-3056). It has to move out of the first-pass prefix. - `build_minimal_daemon_args` (the old `--secluded-args` first pass) is removed. The remote-shell argv already matched 3.5.2 for both pull and push (captured: `--server [--sender] -srRe.iLsfxCIvu --iconv=ISO-8859-1`, then `rsync ... . path`). It is unchanged. ## Measured (oc client, rsync 3.5.2 daemon over a remote shell, module charset ISO-8859-1) | client | `-s` | daemon argv after the fix | exit | copied | |---|---|---|---|---| | rsync 3.5.2 | yes | `-srRe.iLsfxCIvu --iconv=UTF-8` / `rsync --files-from=- --from0 . src/` | 0 | `café` | | oc before | yes | `--secluded-args --iconv=ISO-8859-1` / `rsync --server --sender -rRe... ...` | 23 | nothing | | oc after | yes | byte-identical to 3.5.2 (strace) | 0 | `café` | | rsync 3.5.2 | no | `-rRe.iLsfxCIvu --iconv=UTF-8 --files-from=- --from0 . src/` | 23 | nothing | | oc before | no | `-rRe... --files-from=- --from0 --iconv=ISO-8859-1 . src/` | 23 | nothing | | oc after | no | byte-identical to 3.5.2 (strace) | 23 | nothing | ## Tests - `crates/cli/tests/files_from_iconv_protect_args.rs`: the skip of the oc client to rsync 3.5.2 daemon pairing under `-s` is removed, so `a_daemon_pull_with_protect_args_converts_the_list` now covers it. `a_daemon_pull_without_protect_args_sends_the_list_unconverted` covers the case without `-s`. - `orchestration/tests.rs`: four wire tests check the bytes sent for each pass: a protected pull's first pass (flag string with `s`, local `--iconv`), a protected pull's second pass (`rsync . test/` only), a protected push without iconv, and an unprotected pull with `--iconv` right after the flag string. - Mutation: reverting `arguments.rs` to the base makes all 4 new unit tests fail, and makes `a_daemon_pull_with_protect_args_converts_the_list` fail in the oc client to rsync 3.5.2 daemon pairing (exit 23, nothing copied, where 3.5.2 gives exit 0 and `café`). With the fix all 8 cells pass with `OC_RSYNC_UPSTREAM_COMPAT=1`, and the daemon `module_access` tests pass (342). ## Remaining differences (separate issues) - Sender diagnostics print a non-UTF-8 name lossily (`caf\357\277\275` where 3.5.2 prints `caf\#351`). - An invalid UTF-8 name on a push gives `[receiver] cannot convert filename` plus extra `delete_file` / `could not make way` lines. 3.5.2 prints `[sender] cannot convert filename`. - The oc daemon still accepts the old oc-client first pass (`--secluded-args`), so older oc clients keep working. Closes #8877
oferchen
added a commit
that referenced
this pull request
Nov 27, 2026
## What rsync 3.5.2 does `rwrite()` hands every FERROR/FWARNING/FINFO line to `filtered_fwrite()` before it reaches the terminal: - A client without `-8` opens `ic_chck = iconv_open(cs, cs)` (rsync.c:96-98). `rwrite()` then validates the line in the locale codeset (log.c:463-496). Each rejected byte is written as `\#ooo` (log.c:487), and the valid characters go through `filtered_fwrite(f, convbuf, len, 0, ..)` (log.c:476). - A `-8` client or a server takes `filtered_fwrite(f, buf, len, !allow_8bit_chars, ..)` (log.c:499). - `filtered_char_len()` (log.c:276-293) escapes C0 except TAB, DEL, 0x80-0x9F, and the backslash of a literal `\#ddd` (log.c:288-291). With `use_isprint` it also escapes every byte `isprint()` rejects. - `rwrite()` peels one trailing newline and writes it raw (log.c:460). - A refused filter rule is echoed through `rprintf(FERROR, ...)`: `filter_rule_err()` at exclude.c:133-136 and the `invalid modifier` line at exclude.c:1376. So a VT in the rule prints as `\#13`, both in the `'%c'` detail and in the echoed rule. ## What oc did oc's daemon log file already escaped its lines (`LogFileWriter`, mirroring `logit()` at log.c:143), and so did lines forwarded from a server in MSG frames. Lines the client printed itself were not escaped: - A refused `--filter` rule (`write_refusal`). - Every `Message` written through the client stderr `MessageSink`. - The pre-formatted cause lines of a `ClientError` report. - The local-copy `link_stat ... failed` / `file has vanished` operand lines, which the engine printed with `eprintln!`. ## The fix It reuses the existing escaper in `logging::escape`. There is no second escaper. - `logging::escape`: - `may_need_escaping()` is the fast-path test `escape_for_output` already ran, now split out so sinks can skip the copy. - `write_terminal_line()` / `eprint_terminal_line()` write one escaped stderr line. A clean line goes out with no copy. - `MessageSink`: - A `terminal_escaping` flag, set on the client stderr sink. A message whose text is clean keeps the vectored, allocation-free render. Only a text with something to escape is rendered into a buffer and escaped once. - `write_escaped_line()` for pre-formatted lines. - The style is read at write time, because `-8` and the locale are parsed after the sink is built. - `write_refusal` takes an `EscapeStyle`: - Client: the sink's style. - Server argv: `terminal_style()`, as log.c:499 applies on a server before multiplexing. - Daemon: `passthrough()`. This is deliberate. The daemon's refusal lines also go to its log sink, which escapes on its own as upstream's `logit()` does (log.c:143). Escaping here as well would print `\#134#013`, so each line is still escaped exactly once. - `emit_error_report` sends its cause and program lines through `write_escaped_line`. The remote shell's own stderr is still written as received. ## Measured on Linux, stderr cause line (`od -c`) and exit code | cell | rsync 3.5.2 | oc master | oc with this change | |---|---|---|---| | `--filter=$'+\vfoo'` | `invalid modifier '\#13' at position 1 in filter rule: +\#013foo`, exit 1 | raw `\v` twice, exit 1 | `invalid modifier '\#13' at position 1 in filter rule: +\#013foo`, exit 1 | | `--filter=$'foo\vbar'` | `Unknown filter rule: foo\#013bar`, exit 1 | raw `\v`, exit 1 | `Unknown filter rule: foo\#013bar`, exit 1 | | missing operand `no\001pe` | `link_stat ".../no\#001pe" failed`, exit 23 | raw `\001` on both lines, exit 23 | `link_stat ".../no\#001pe" failed` on both lines, exit 23 | | same, forwarded from a remote server | `\#1`, exit 23 | `\#1`, exit 23 | `\#1`, exit 23 (unchanged) | | missing operand `no\tpe` | raw TAB, exit 23 | raw TAB, exit 23 | raw TAB, exit 23 | | operand `café\001`, `LC_ALL=C` | `caf\#303\#251\#1` | raw | `caf\#303\#251\#1` | | operand `café\001`, `-8` or `C.UTF-8` | `caf` + raw `é` + `\#1` | raw | `caf` + raw `é` + `\#1` | ## Tests - `crates/cli/tests/client_stderr_control_byte_escaping.rs`: - Three oracle cells against rsync 3.5.2: VT in a refused modifier, the same under `-8`, and a control byte in an unknown rule. Each compares the cause line byte for byte, plus the exit code. - One cell for a control byte in a missing operand. It checks the escaping and exit 23, not the whole line, because the surrounding wording still differs (see below). - `MessageSink` unit tests, one per byte class: - C0 escaped and TAB raw. - DEL and high/C1 bytes. - The literal `\#ddd` guard. - An embedded newline staying on one line. - A raw trailing newline. - `write_escaped_line`. - Unit tests for `write_refusal` (VT) and `write_terminal_line`. Mutation: with the escaping switched off at each new site (the client sink flag, the `write_refusal` style, `MessageSink::escape_style`, `write_terminal_line`), all 12 new tests fail: 4/4 cli, 6/6 logging-sink, 1/1 core, 1/1 logging. ## Multi-line causes Escaping showed that oc folded some multi-line diagnostics into one line. Each such cause is now written one line per upstream `rprintf` call: - `Unexpected local arg: %s` and `If arg is a remote file/dir, prefix it with a colon (:).` are two `rprintf(FERROR, ...)` calls in 3.5.2 (main.c:1591-1592). oc built one cause with an embedded newline, so escaping printed `\#12` between the two parts. A `ClientError` cause now holds one line per upstream call (`cause_lines()`), and the report writes each line through the escaper. A newline inside the operand itself is still escaped as `\#12`, as log.c:288-291 does. - clap's parse error spans several lines. oc writes it line by line, so its own line breaks stay raw and only bytes inside each line are escaped. Upstream prints its option error as one popt line through `option_error()` (options.c:2087-2090, options.c:933), then the trailer (main.c:1916-1917). The wording differs, and this PR does not change it: - 3.5.2: `rsync: --version=extra: option does not take an argument`, then `rsync error: syntax or usage error (code 1) at main.c(1917) [client=3.5.2]` - oc: `rsync error: syntax or usage error: unexpected value 'extra' for '--version...' found; no more were expected`, a blank line, `Usage: rsync --version... [args]...`, then ` (code 1) [client=...]` - The unknown-option refusal and the failed `--log-file` open line were raw writes. They now go through the escaper too. Measured: 3.5.2 prints `rsync: --bo\#001gus: unknown option`, and oc now prints the same line. - A daemon that sends free text and then closes before acknowledging a module listing used to be reported as one message, with the received lines joined by newlines. Escaping would have printed `\#12` between them. Upstream prints each received line with its own `rprintf` (clientserver.c:428-429 for `@ERROR`, 438-439 for MOTD and listing lines). Each received line is now its own escaped stderr line, followed by the existing `daemon refused module listing` trailer. The trailer no longer repeats the lines. The connect-failure lines on that path also go through the escaper now. New tests in `crates/cli/src/frontend/tests/stderr_lines.rs`. Each one fails with the split reverted: - the local-after-remote refusal prints 3 lines, and a newline in the operand prints as `\#12` - a parse error keeps its lines - an unknown option is escaped - a daemon refusal prints one stderr line per received line, with a control byte escaped (plus a core `module_list` test that the refusal keeps one cause line per received line) ## Gates (Linux host, on master 0c57d58) | gate | exit | |---|---| | `cargo fmt --all -- --check` | 0 | | `python3 tools/ci/check_rustfmt_all.py` | 0 | | clippy on logging, logging-sink, core, cli, daemon, engine (`--all-targets --all-features -D warnings`) | 0 | | `cargo check --workspace --all-features --all-targets --target x86_64-pc-windows-gnu` | 0 | | `cargo clippy --workspace --all-features --all-targets --target x86_64-pc-windows-gnu --no-deps -- -D warnings` | 0 | | `cargo run --locked -p xtask -- no-placeholders` | 0 | | `tools/ci/citation_drift_audit.py --ratchet` | 0 | | new oracle file vs rsync 3.5.2 (`OC_RSYNC_UPSTREAM_COMPAT=1`) | 0 (4/4) | | cli `--lib` (all frontend unit tests) | 0 (3142/3142) | | cli `stderr_lines` + `clap` under `LC_ALL=C` and `LC_ALL=en_US.UTF-8` | 0 (7/7 each) | | cli summary/filters/argv_filters/refusal/filter_rule units | 0 (67/67) | | cli `module` (module listing) | 0 (20/20) | | core `module_list` | 0 (269/269) | | daemon `/list/` | 0 (118/118) | | cli `client_output_locale_escaping`, `upstream_compat_filter_rule_parse` | 0 (31/31) | | bin `ssh_transport` | 0 (15/15) | | test-support `daemon_pull_every_operand` | 0 (10/10) | | core `filter_args`, `client::error` | 0 (357/357) | | core `client::remote::invocation` | 0 (322/322) | | logging-sink `message_sink` | 0 (63/63) | | logging `escape` | 0 (50/50) | | engine orchestration/link_stat/vanished | 0 (20/20) | | daemon `/argv_filters/`, `/daemon_filter/` | 0 (39/39) | ## Remaining differences - The missing-operand report is worded differently from 3.5.2. oc prints a bare `link_stat ...` line, then an `rsync error: link_stat ... (code 23)` trailer. 3.5.2 prints `rsync: [sender] link_stat ...`, then `some files/attrs were not transferred ... (code 23)`. That is a separate text-parity gap; this change only fixes the escaping. - Other raw `eprintln!` diagnostics in the local-copy engine carry names that are not escaped yet. Examples: `symlink has no referent`, `opendir`, `directory has vanished`, and the skip notices. They can move to `eprint_terminal_line()` one by one. - The same applies to the remaining raw stderr writes of an oc `--server`, and to the copy of a daemon's refusal on its own stderr. - Stdout escaping is untouched. The escaping of valid UTF-8 names on stdout is tracked separately. Closes #8884
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.
Summary
Testing