Skip to content

fix: refuse a tab as a filter rule separator like rsync - #8873

Merged
oferchen merged 1 commit into
masterfrom
fix/filter-rule-separator-whitespace
Nov 27, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/filter-rule-separator-whitespace

Conversation

@oferchen

Copy link
Copy Markdown
Owner

What rsync 3.5.2 does

parse_rule_tok() reads a rule's modifiers in one loop that stops only at ' ' or '_':

while (ch != '!' && *++s && *s != ' ' && *s != '_') {   /* exclude.c:1365 */

Any other byte goes to the switch default and the invalid: label (exclude.c:1371-1380), which exits RERR_SYNTAX (1).

rule_strcmp() ends a long keyword at any isspace byte, _, , or NUL (exclude.c:1222). For every terminator except , it returns str + rule_len - 1, so the loop's *++s lands on the terminator itself. A space or _ stops the loop. A tab, VT, FF, CR or LF is read as the first modifier byte and refused.

So a tab after a short prefix (-, +, H, ., : ...), after a modifier (-p), or after a keyword (exclude, merge, hide ...) is an error, not a separator. Under the w (word-split) merge modifier the file is split on all whitespace before parsing (exclude.c:1772), so tabs never reach the loop there.

What oc did

Three parsers counted every ASCII whitespace byte as a separator:

  • the client parser for arguments and merge files (crates/core/src/client/filter_args/parsing)
  • the merge-file parser in crates/filters/src/merge/parse.rs (long keywords only; short forms were already correct)
  • the local-copy per-directory parser (crates/engine/src/local_copy/dir_merge/parse), for keywords and H/S/P/R

--filter=$'-\tfoo' excluded foo and exited 0.

The fix

  • Each parser now ends the modifier run at ' ' or '_' only. The core is_rule_separator used to carry a comment admitting the deviation; that comment is gone.
  • After a keyword, any other isspace byte becomes the start of the modifier run. The shared modifier table then refuses it at its rule position: 7 for exclude<TAB>, 9 for exclude,p<TAB>.
  • filters::is_c_isspace is now public and is the one definition of C's isspace set. Rust's is_ascii_whitespace leaves out VT.
  • Core parse_keyword_rule now splits its keyword through the same split_long_keyword_tail that the merge directives use. Two helpers had no callers left and were removed: consume_rule_separator and split_keyword_modifiers.

Measured: 3.5.2 vs oc (host, local copy, tree holds foo, foo, bar)

rule source 3.5.2 oc before oc after
-<TAB>foo --filter exit 1, invalid modifier '<TAB>' at position 1 exit 0, foo excluded = 3.5.2
+<TAB>foo --filter exit 1, position 1 exit 0 = 3.5.2
-p<TAB>foo --filter exit 1, position 2 exit 0 = 3.5.2
-<TAB> --filter exit 1, invalid modifier ... position 1 exit 1, unexpected end of filter rule = 3.5.2
exclude<TAB>foo --filter exit 1, position 7 exit 0 = 3.5.2
- foo, -_foo, exclude foo, exclude_foo --filter exit 0, foo excluded same same
- foo, exclude foo --filter exit 0, foo excluded same same
-<TAB>foo, exclude<TAB>foo, +<TAB>bar, -p<TAB>foo . FILE merge exit 1, invalid modifier in filter rule: <rule from FILE line 1> exit 0 = 3.5.2
merge<TAB>FILE . FILE merge exit 1, redacted invalid modifier exit 0 = 3.5.2
exclude<TAB>foo, H<TAB>foo -F .rsync-filter (local) exit 1, redacted invalid modifier exit 0 = 3.5.2
any line .w FILE merge unexpected end / parse, by word same same
-<TAB>foo --exclude (old prefixes) literal pattern, exit 0 same same

After the fix, the 31-row measurement matrix (--filter, . FILE, .w FILE, nested merge; tab, space, _, double space) is byte-identical to 3.5.2 once the program name and source location are normalised.

Tests

  • filters: merge::tests::rule_separator_is_space_or_underscore_only (table, 18 rows). It replaces long_form_keyword_tab_separator, which asserted the wrong behaviour.
  • core: parsing::tests::rule_separator_is_space_or_underscore_for_every_rule_form (21 rows through parse_filter_directive, exact message and position). Also helpers::tests::split_modifier_run_ends_only_at_space_or_underscore, long_keyword_refuses_non_space_whitespace_as_a_modifier and long_keyword_needs_a_terminator.
  • engine: line::tests::rule_separator_is_space_or_underscore_only and split_keyword_modifiers_keeps_non_space_whitespace_as_a_modifier.
  • Oracle cell cli/tests/upstream_compat_filter_rule_parse.rs::only_space_or_underscore_separates_a_rule_from_its_pattern. It compares exit code, first diagnostic line, trailer and transferred files with 3.5.2 for 14 --filter rules. It also runs 6 merge-file lines three ways: through . FILE, through -F locally, and through -F on a push.

Results: oracle file 24/24 with OC_RSYNC_UPSTREAM_COMPAT=1; filters 1595/1595; core filter_args 303/303; engine dir_merge 210/210.

Mutations (each reverted afterwards), all killed:

mutation failing tests
core separator accepts all whitespace again 3 core tests
core keyword tail drops the isspace arm 2 core tests
filters long form takes isspace as a separator filters table test
engine token splits on all whitespace again engine table test
engine keyword tail drops the isspace arm engine table test

The oracle cell found the engine parser. Before that, only core and filters were changed.

Remaining differences (not in this PR)

  • Control-byte escaping in client diagnostics. 3.5.2 prints a VT in a refused --filter rule as \#013, both in the '%c' detail and in the echoed rule. oc prints the raw byte. This is upstream's general output escaping of non-printable bytes, not the parser. oc escapes the daemon log file (logging-sink) but not client stderr. The VT row was dropped from the oracle cell for this reason; the unit tests still pin the parse decision for VT. A tab is not escaped by 3.5.2 and matches.
  • Engine single-letter prefix glued to a modifier (for example Hp foo in a .rsync-filter). The engine tokenises it as the unknown keyword Hp. This is unchanged here and was not measured.

Closes #8738

rsync 3.5.2 ends a rule's modifier run only at ' ' or '_'
(exclude.c:1365). rule_strcmp() ends a long keyword at any isspace
byte (exclude.c:1222), but the modifier loop then lands on that byte,
so a tab or other non-space whitespace after a prefix, a modifier or a
keyword reaches the invalid: label and exits 1 with
"invalid modifier '<ch>' at position <n> in filter rule: <rule>"
(exclude.c:1371-1380), or the redacted "invalid modifier in filter
rule: <rule from FILE line N>" for a rule read from a file.

oc treated every ASCII whitespace byte as a separator in three rule
parsers: the client argument and merge-file parser (core), the
merge-file parser in the filters crate, and the local-copy
per-directory parser (engine). `-<TAB>foo`, `exclude<TAB>foo`,
`H<TAB>foo` and friends were accepted and excluded `foo`.

Each parser now ends the modifier run at ' ' or '_' only and hands
any other isspace byte after a keyword to the modifier table, which
refuses it at its rule position. A shared `filters::is_c_isspace`
gives the C isspace set (Rust's is_ascii_whitespace omits the
vertical tab). Word-split (`w`) merge files are unchanged; they
already split on all whitespace before parsing (exclude.c:1772).
@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
@oferchen
oferchen merged commit 35156a0 into master Nov 27, 2026
90 checks passed
@oferchen
oferchen deleted the fix/filter-rule-separator-whitespace branch November 27, 2026 05:51
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

1 participant