Repository navigation
fix: refuse a tab as a filter rule separator like rsync - #8873
Merged
Merged
Conversation
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).
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.
What rsync 3.5.2 does
parse_rule_tok()reads a rule's modifiers in one loop that stops only at' 'or'_':Any other byte goes to the
switchdefault and theinvalid:label (exclude.c:1371-1380), which exitsRERR_SYNTAX(1).rule_strcmp()ends a long keyword at anyisspacebyte,_,,or NUL (exclude.c:1222). For every terminator except,it returnsstr + rule_len - 1, so the loop's*++slands 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 thew(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:
crates/core/src/client/filter_args/parsing)crates/filters/src/merge/parse.rs(long keywords only; short forms were already correct)crates/engine/src/local_copy/dir_merge/parse), for keywords andH/S/P/R--filter=$'-\tfoo'excludedfooand exited 0.The fix
' 'or'_'only. The coreis_rule_separatorused to carry a comment admitting the deviation; that comment is gone.isspacebyte becomes the start of the modifier run. The shared modifier table then refuses it at its rule position: 7 forexclude<TAB>, 9 forexclude,p<TAB>.filters::is_c_isspaceis now public and is the one definition of C'sisspaceset. Rust'sis_ascii_whitespaceleaves out VT.parse_keyword_rulenow splits its keyword through the samesplit_long_keyword_tailthat the merge directives use. Two helpers had no callers left and were removed:consume_rule_separatorandsplit_keyword_modifiers.Measured: 3.5.2 vs oc (host, local copy, tree holds
foo,foo,bar)-<TAB>foo--filterinvalid modifier '<TAB>' at position 1fooexcluded+<TAB>foo--filter-p<TAB>foo--filter-<TAB>--filterinvalid modifier ... position 1unexpected end of filter ruleexclude<TAB>foo--filter- foo,-_foo,exclude foo,exclude_foo--filterfooexcluded- foo,exclude foo--filterfooexcluded-<TAB>foo,exclude<TAB>foo,+<TAB>bar,-p<TAB>foo. FILEmergeinvalid modifier in filter rule: <rule from FILE line 1>merge<TAB>FILE. FILEmergeexclude<TAB>foo,H<TAB>foo-F.rsync-filter(local).w FILEmergeunexpected end/ parse, by word-<TAB>foo--exclude(old prefixes)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 replaceslong_form_keyword_tab_separator, which asserted the wrong behaviour.core:parsing::tests::rule_separator_is_space_or_underscore_for_every_rule_form(21 rows throughparse_filter_directive, exact message and position). Alsohelpers::tests::split_modifier_run_ends_only_at_space_or_underscore,long_keyword_refuses_non_space_whitespace_as_a_modifierandlong_keyword_needs_a_terminator.engine:line::tests::rule_separator_is_space_or_underscore_onlyandsplit_keyword_modifiers_keeps_non_space_whitespace_as_a_modifier.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--filterrules. It also runs 6 merge-file lines three ways: through. FILE, through-Flocally, and through-Fon a push.Results: oracle file 24/24 with
OC_RSYNC_UPSTREAM_COMPAT=1;filters1595/1595;corefilter_args 303/303;enginedir_merge 210/210.Mutations (each reverted afterwards), all killed:
The oracle cell found the engine parser. Before that, only
coreandfilterswere changed.Remaining differences (not in this PR)
--filterrule 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.Hp fooin a.rsync-filter). The engine tokenises it as the unknown keywordHp. This is unchanged here and was not measured.Closes #8738