Repository navigation
fix(expand): #843 — E400-escape user PUA codepoints in the patsub replacement pipeline - #853
Merged
Merged
Conversation
…t pipeline (rubash#843)
The replacement side of ${var/pat/rep} carries user data that may legally
be a registry-zone glyph: GNU 5.3.0 prints ${v/b/$'\uE312x'} as
a<E312>xc (subst.c:4462 expand_string_for_rhs feeds the replacement through
expand_word_internal as its own word; strcreplace stringlib.c:180 flags-2
only touches a literal &/\&/\\). rubash's pipeline consumed bare
E310-E313 as its own PATSUB markers — E312 rendered as '&' through the
\\& path, E310/E311 dropped as quoted-value region toggles, E313 as '\\'.
Fix (the #735 mechanism applied in flight): the scan pass E400-escapes
every literal registry-zone char it copies (push_replacement_literal —
replacement body, '...' spans, dquote spans, backslash escapes, literal
next-char after $); the ANSI-C $'...' span escapes typed glyphs at body
collection; finish_patsub_replacement copies E400/E000 pairs verbatim
before resolving markers, and its #838 leak probe (strip_escape_pairs)
asserts only LIVE markers — an escaped codepoint in the output is restored
user data. The raw-byte introducer E000 stays verbatim (owning the pair
protocol; an E400 prefix would split a pair, the #296 frozen-carrier
class). markers.rs: PATSUB family documented user_reachable with the
in-flight escape contract; governance 3.2 table gains the patsub row.
Verification: WSL GNU 5.3.0 script-file oracles oracle843.sh/oracle843b.sh
(15+11 forms: E310/E311/E312/E313 + & and \\& refs + // global + rep-var
+ raw-byte payloads + typed literals + declare -p + %q + shopt-off +
E400/E401 edges) byte-identical rubash-vs-GNU; new
tests/issue843_patsub_pua_escape_regressions.rs (12 cases, all failing on
master); marker_leak_golden 8/8; #838 issue824_marker_decode_boundary_
regressions 8/8; #323 patsub ANSI-C 11/11; lib 689/689; fmt clean;
RUSTFLAGS=-D warnings cargo check clean.
Member
Author
独立代码评审:APPROVE-WITH-NITS独立复核轮(自建 worktree @ dab4ad7,基线 worktree @ 8e9c7c0,全部验证实做)。无 BLOCKER。 核心审计(转义完备性)
GNU 语义与坐标
回归
NITS(非阻塞)
结论:APPROVE-WITH-NITS。机制正确、边界自洽、验证扎实,三条 nit 均为文档/记录层面,不阻塞合并。 |
This was referenced Oct 19, 2026
Merged
7 tasks done
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.
Closes #843. Based on master
8e9c7c0f(merge of origin/master brought in mid-task per the #577 discipline; re-verified on the merged tree). Not merged from my side.Root cause
The patsub replacement pipeline's own markers (PATSUB_QUOTED_VALUE_START/END/AMP/BACKSLASH, U+E310-E313) share the registry zone with user data, and nothing escaped user zone glyphs in flight: the scan pass copied literal replacement chars raw, and
finish_patsub_replacementresolved any bare E310-E313 — including the user's own — as pipeline protocol:${v/b/$'\uE312x'}→a&xc(E312 read as PATSUB_QUOTED_AMP, rendered through the\\&path)axc(consumed as quoted-value region toggles and dropped)a\\xc(read as PATSUB_QUOTED_BACKSLASH)Reproduced on release builds; ticket tri-verified. GNU 5.3.0 treats the replacement as its own word (subst.c:4462
expand_string_for_rhs→parameter_brace_patsub:9424-9444) and strcreplace (stringlib.c:180, flags 2 via pat_subst:9252) only touches a literal&/\&/\\ — a U+E3xx glyph rides verbatim. The four #838 PATSUB leak asserts were never the leak: they consume in flight, and the entry side (this fix) is what let bare user codepoints reach them.Fix — the #735 E400 mechanism applied in flight (
src/executor/expand_braced_replacement.rs)push_replacement_literal→markers::push_literal_char(E400 prefix): the mainotherarm,'...'spans, double-quoted spans, backslash escapes, and the literal next-char after an unexpandable$. The raw-byte introducer E000 stays verbatim (it owns the pair protocol; an E400 prefix would split a pair — the [bug] Assignment RHS: control-byte var adjacent to live $() leaks U+E000+U+E0xx carrier pair into stored value (argument position clean) — corrupts OMB binaryanomaly/rjorgenson PS1 #296 frozen-carrier class).$'...'bodies escape typed zone glyphs at body collection;\\u-decoded codepoints are already pair-escaped by the canonical decoder, so decoded content copies verbatim (re-escaping would double-encode the pair — one decode at the output boundary would then restore the wrong text).finish_patsub_replacementcopies E400+c and E000+payload pairs verbatim before resolving markers, so escaped user data can never be read as a live marker regardless of which entry arm produced it (inline$'...', stored-variable expansion, raw typed glyphs).strip_escape_pairs(output)— only LIVE markers assert; an escaped codepoint in the output is restored user data (${v/b/$'\uE312x'}emits U+E312). markers.rs: the four PATSUB markers registeruser_reachable: truewith the in-flight escape contract documented; governance 3.2 table gains the patsub row.GNU differential (WSL GNU bash 5.3.0, script-file oracle, byte-exact)
All forms byte-identical rubash-vs-GNU after the fix (master red on the PUA shapes):
${v/b/$'\\uE312x'}(and E310/E311/E313)a+ glyph +xca&xc/axc/a\\xc${v/b/&$'\\uE312'}(match ref)ab+ glyph +cab&c${v/b/\\&$'\\uE312'}a&+ glyph +ca&&c${w//b/$'\\uE312x'}(global)&corruption${v/b/$rep}(storage pair path)a&xc$'\\x10'..$'\\x13''...')&declare -p/printf %q/ echo double-echo&&\\1reference formsa1cetc.Oracles:
oracle843.sh(15 forms),oracle843b.sh(11),oracle843c.sh(3) — run ascat script | wsl.exe bash -s, output od-compared byte-for-byte.Tests
tests/issue843_patsub_pua_escape_regressions.rs(12 cases): tri-codepoint ANSI-C forms,&/\& refs, global//, storage-pair rep form, raw-byte payloads, typed literals,declare -p, shopt-off, E400/E401 edges, stray-introducer guard. Core shapes verified red on master.issue824_marker_decode_boundary_regressions8/8, [bug] ANSI-C escapes not decoded in the replacement operand of ${var//pat/$'\n'}: literal backslash-n stored ($'\t' too; $'\xHH' works) #323 patsub ANSI-C 11/11, user-typed PUA codepoints collide with the marker registry: ANSI-C E401 is silently swallowed (data loss); E301/E314 miscount as length 2 #735 5/5, lib 689/689.cargo fmt --checkclean;RUSTFLAGS="-D warnings" cargo checkclean; clippy warnings in touched files all pre-existing (verified present at b79e678).Full dual-direction suite (--no-fail-fast --test-threads=1)
windows_listing_cache…, green serially on both trees)profiler_regressions fixture_text_tree— reproduces on pure 8e9c7c0 (5/6 runs red there, 4/5 on the branch): pre-existing master-side #815 report-ordering flake, unrelated to this change (no src delta between the trees)Zero new failures, zero lost fixes; local environment failures within the known ~37-44 baseline band.