Skip to content

Refs #3104: fold raw-byte (E000) pairs at name-consumption boundaries - #3122

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/3104-e000-name-boundaries
Nov 9, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/3104-e000-name-boundaries

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

返工完成(队长复核 NOT-PASS 终判 2026-11-09 17:18 CST 的三项,2026-11-09 18:42 CST)

  • 钉断言修正:4 格(redirect_var / comsub / ansic / history_write)的 !names.any(pair head) 误杀夹具自带的真 U+E000 对照文件 u\u{E000}v;改为 pair 扫描排除该已知真字符文件(pair_headed helper)。只改测试文件,提交 e0946497。
  • 真产品缺陷:PATH 查找经字节名目录仍失败(path_lookup_finds_byte_named_dir_and_command rc=127、type_reports_raw_byte_path 空输出)。根因:PATH 分割/查找消费点未对字节名目录分量折对,findcmd 侧未走共享 helper。修法见下,提交 6e03cd18。
  • p23 高字节面同波:0x9C 被重编为 UTF-8(GNU a\x9cb vs 旧头 a\xc2\x9cb);字节字符→路径字节按原始字节发射。新增 p23 钉格 + é 对照格,茎由 22 格变为 24 格(基底 fail-first 由 3/19 变为 4/20)。
  • 验证(重验全绿,数字见 REPORT):钉头 24/24;基底 fail-first 4/20 逐格干净;lib 头/基底双边 1206/0/4;邻茎 67 格全绿;GNU 探针与 GNU 只差 p20 一行(enable -f 诊断措辞,记录而已);RUSTFLAGS="-D warnings" rc=0;marker-lint rc=0;fmt rc=0。
  • 死线实话:返工 + 本地重验已于今日完成,但 fresh CI 今日赶不上——不许为赶死线带红合入,本 PR 保持 draft,等队长复核与 fresh CI。详见 ~/workspace/fix-3104/REPORT.md §5–§6。

Refs #3104

问题

存储值中的原始字节以 U+E000 原始字节对(E000 + 载荷字)传输。#3076 在全部名字消费边界以共享门 + 边界解码器折回了 E400 字面转义对,但共享 helper fold_literal_char_escapes 的门只认 E400 引入符——纯 E000 对的文本不触发折叠,于是同一批边界在 E000 域原样泄漏:

  • 重定向目标落盘为对拼写名(单字节 0x1C 落成 EE 80 80 EE 80 9D 六字节);变量形、comsub 直形、$'...' 形同漏(redir.c:298:redirection_expand 返回的串即 open 的串)。
  • test / [ / [[ ]] 操作数(一元 + 二元)探对名 → 既存文件报假(test.c:549-559)。
  • source(source.def:179)、cd(cd.def:427)、pushd、$(cd … && pwd) 快路径解析对名失败。
  • PATH 查找(findcmd.c:348/623:对名目录项 + 对名命令双形)、slash 名 spawn 与 exec(execute_cmd.c:6139 原始词字节)找不到既存可执行文件;type 报对拼写。
  • glob 字面段与 readdir 名永不相等;bind -f 读对名失败;history -w 落对拼写名。
  • $(< file) 快路径(optimize_cat_file,subst.c:6665 / evalstring.c:759)自有定型点、不经共享 helper,同样不折对。

#3004 已在仿真文件内建面以双族门 contains_decodable_transport + 同一解码器修复同域问题;本单是其余名字消费边界的 E000 对应面(#3076 普查 #26 记录域)。

修法(按机制)

  1. substitution_metadata::fold_literal_char_escapes 的门由「仅 E400 引入符」放宽为双族门 markers::contains_decodable_transport(E000 引入符或 E400 引入符,expand_prompt renders the E400 escape pair for a stored U+E314 value instead of the raw char #3038 既有门)——解码器本体 decode_raw_byte_markers_to_byte_chars 本就双族全解(E000 对 → byte char、E000E000 → 字面 U+E000、E400 对 → 原字)。E400 literal-char pairs leak at command-lookup / slash-execve-classification / cd / exec operand boundaries (same family as #3040) #3076 普查的全部边界(PATH/hash 键、slash 分类、cd/pushd、exec 诊断、source、test、glob、history/bind/enable 文件操作数、comsub cd 快路径、重定向定型与 failglob 诊断)经此一门同解,不按命令逐个打补丁。
  2. command_substitution::comsub_cat_file_substitute:$(< file) 的词定型后(字段分裂/glob 之后、fs 读之前)在同一 helper 折对——该面是普查中唯一不经共享 helper 的名字消费点。
  3. 返工新增——PATH 查找折对(findcmd.c:348 search_for_command / :623 find_user_command_in_path):path.rs::find_in_path_walk_unix 对每个 PATH 分量亦经 fold_literal_char_escapes 折对;目录与命令名按字节拼探测路径(OsStr::from_bytes),as-written 拼写仍为折叠串(type 打印 / $0 记录的拼写)。slash 与 exec 面已绿,不动。
  4. 返工新增——字节字符→路径字节按原始字节发射:新 helper folded_name_to_path_bytes(U+0000..=U+00FF 的 byte char 发单字节,其余发 UTF-8)+ path_buf_from_folded_name;重定向目标在展开点记 redirect_target_had_transport(仅字面臂记录,glob/procsub/heredoc 臂不记),经中央输出/追加/输入漏斗与散落的 10 处重定向打开点统一走字节路径。真 UTF-8 名(无 transport)不受影响,由 é 对照格钉住。

本 PR 删除了什么

  • 删除了 fold_literal_char_escapes 的单族门条件(E400-only 把关)——它正是 E000 域在全部共享边界泄漏的单一根因。
  • 返工删除了 PATH 查找「分量不折对、按折叠串拼探测路径」的旧行为(探测路径改为字节拼);重定向目标的旧「折叠串直传 open」行为改为按 transport 旗标走字节路径。
  • 无其他删除。解码器与各边界调用点均不改。

验证

  • 回归钉 tests/issue3104_e000_name_consumers.rs(24 格,含落盘名字节断言):头 24/24;基底 fail-first 4 绿 / 20 红,逐格干净(13 机制格 + 4 钉 bug 格 + path_lookup + type + p23 均基底红/头绿;4 绿格为 3 旧双绿 + é 对照)。
  • GNU 探针矩阵 26 形(~/workspace/fix-3104/probes,GNU 5.3.20 / 基底 / 修复树三方):修复后与 GNU 只差 p20 一行(enable -f 诊断措辞差异,记录而已,不修不立);p07/p11/p23 均与 GNU 逐字节一致。
  • lib 头/基底双边 1206/0/4(失败名集皆空,一致);邻茎 67 格全绿(E400 literal-char pairs leak at command-lookup / slash-execve-classification / cd / exec operand boundaries (same family as #3040) #3076 24、__git_complete_index_file 对含 \x1c–\x1f 字节的文件名返回空候选(t9902 #165) #3004 12、marker_leak_golden 21、marker_registry 10);RUSTFLAGS="-D warnings" rc=0;marker-lint rc=0;fmt rc=0。
  • 残余:同一名字内真 Latin-1 字与 byte char 混用时同取字节拼写(见 REPORT §5);type 对 0x9C 目录的显示仍为 UTF-8 形(p11 为 0x1C,不在范围)。各腿数字见 REPORT(~/workspace/fix-3104/REPORT.md)。

…aries (Refs #3104)

22 cells mirroring the GNU bash 5.3.20 probe matrix: redirect
targets (variable / comsub / ANSI-C forms) with on-disk name-byte
assertions, test and [[ ]] operands (unary + binary), source, cd,
pushd, the $(cd ...) fast path, PATH lookup, slash-name spawn,
exec, type, command-not-found diagnostic, glob literal segments,
bind -f, history -w, $(< file), read redirect, plus plain-name
and genuine-U+E000 controls. Fail-first on the base: the defect
cells fail, the controls pass.
…#3104)

fold_literal_char_escapes gated on the E400 introducer alone, so
a name carrying only a U+E000 raw-byte pair never folded: the
pair spelling reached filesystem probes, lookup cache keys, and
diagnostics at every boundary the rubash#3076 census routed
through the shared gate + decoder (PATH/hash keys, slash-name
classification, cd/pushd operands and substituted values, exec,
source, test operands, glob patterns, history/bind/enable file
operands, the comsub cd fast path, redirect operand
finalization and the failglob diagnostic). The decoder already
folds both families; the gate is now the shared double-family
gate contains_decodable_transport (rubash#3038) — one gate for
the whole census, no per-command patching. GNU ownership: the
expanded word IS the name (redir.c:298, findcmd.c:348/623,
execute_cmd.c:6139, cd.def:427, source.def:179, test.c:549-559).

The $(< file) reader (optimize_cat_file, subst.c:6665 /
builtins/evalstring.c:759) finalizes its own word and never
passes the shared helper; fold its finalized file_word through
the same gate + decoder before the open.

The marker-lint allowlist entry for the removed single-family
gate line goes with it (stale entry); pin file fmt touch-up.
… scans; pin the p23 high-byte redirect (Refs #3104)

The pair-head assertion in redirect_var / redirect_comsub /
redirect_ansic / history_write scanned every entry name for the
U+E000 pair head, including the fixture's own genuine-U+E000
control file u\u{E000}v (bytes [117, 238, 128, 128, 118]) — the
four cells red on any tree, including a tree whose products land
the raw-byte names correctly. The scan now skips exactly that
known control file.

Adds the p23 regression pin (probe p23: a stored 0x9C byte in a
redirect target must land as the single raw byte, not UTF-8
re-encoded) and a UTF-8 control pin (a genuine non-ASCII name
keeps its UTF-8 bytes). GNU oracle: redir.c:298.
…th bytes (Refs #3104)

Two gaps the NOT-PASS review found, plus the p23 high-byte face
in the same wave:

1. PATH lookup never folded the directory components: PATH
   "$PWD/bin\x1cd:$PATH" probed the unfolded pair spelling,
   so findcmd never saw the byte-named directory. The unix walk
   now folds each element (gated on the element's own transport)
   and converts each side to filesystem bytes only when it carried
   transport; the as-written join stays the folded string spelling
   for `type`/\$0. The Windows listings scaffold folds its
   elements the same way (the folded string is already the WTF-8
   spelling there). GNU anchor: findcmd.c:348 search_for_command /
   findcmd.c:623 find_user_command_in_path walk PATH with the
   element bytes verbatim.

2. p23: a folded byte char >= 0x80 was re-encoded as UTF-8 at
   every name -> path conversion (0x9C landed as C2 9C; 0x1C
   passed only because it is < 0x80). A folded name cannot tell
   a byte char from a genuine char of the same code point, so the
   pre-fold transport fact is now carried explicitly: the PATH
   walk takes it as a parameter, redirect targets record it in a
   per-command memo set keyed by the folded target string, and
   the $() reader records it at its own fold site. The new
   folded_name_to_path_bytes / path_buf_from_folded_name funnel
   emits byte chars as raw bytes and every other char as UTF-8,
   applied at the redirect output/append/input opens and the
   $(< file) reader. GNU anchor: redir.c:298 redirection_expand
   opens the name bytes verbatim.

Residual recorded in REPORT: genuine Latin-1 chars mixed into
one name with a raw-byte pair share the byte char's code point
and take the byte spelling. The same funnel also covers the
input-redirect open, the append opens, the <> readwrite opens,
and the $(< file) reader.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant