Repository navigation
fix(executor): read -n/-N counts bytes in a single-byte locale (Refs #3334) - #3477
Merged
Merged
Conversation
…3334) StdinCharDecoder::next_unit grouped a valid UTF-8 sequence into one Char unit even when !is_multi_byte(), so `read -n 1` over `é` (c3 a9) under LC_ALL=C took both bytes. GNU builtins/read.def:874 only calls read_mbchar when mb_cur_max > 1; with MB_CUR_MAX == 1 every byte is one unit (nr++ per byte, read.def:880-886). The single-byte branch now returns one byte per unit (ASCII stays Char, high bytes ride as raw-byte units); the multibyte branch is untouched. The guarded `byte as char` widening is allowlisted in check-utf8-boundary-hygiene.sh (`if byte < 0x80` arm; the else arm routes >= 0x80 to raw_byte_unit). Regression nails: tests/issue3334_read_n_bytes_c_locale.rs (9 cases: -n 1/-n 2/-N 1/-N 2 + sequential reads + ASCII/plain/C.utf8 controls), seeded from the issue's GNU 5.3.20 oracle expectations. UNVERIFIED-BY-CAPTAIN
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(逐项):
F 点:无。 续作记录:无(未动代码)。 未跑/VOID 的腿:无。全部 9 腿已跑完并留证(探针脚本在 target/devin-w8-audit/)。 |
Member
Author
|
【WIN-AGENT-BATCH-SUMMARY】
阻塞/共用事实:
|
caomengxuan666
marked this pull request as ready for review
November 15, 2026 02:10
This was referenced Nov 15, 2026
caomengxuan666
added a commit
that referenced
this pull request
Nov 17, 2026
…3785) (#3810) * test: pin read -n/-N byte counting in C locale on redirect/pipeline stdin (Refs #3785) Regression nails for rubash#3785: read -n/-N must count BYTES in a single-byte locale (GNU builtins/read.def:851,874,880-886) on every stdin shape, not only inherited stdin (#3477 fixed that face only). 20 nails: < file, -N < file, -n 1, 0<file, EOF rc, <<< (-n/-N), pipeline brace/parens/function (-n and -N), sequential -n 1 reads, pipeline EOF rc, < /dev/stdin, plus controls (inherited stdin, group redirect, C.utf8 char counting, ASCII, plain read). * fix(executor): count bytes for read -n/-N in single-byte locale (Refs #3785) GNU builtins/read.def:851,874 calls read_mbchar only when mb_cur_max > 1; with MB_CUR_MAX == 1 every byte is one unit (nr++ per byte, read.def:880-886). Three serves still counted characters in LC_ALL=C: - byte_unit_scan_applies: the FUNCTION_STDIN mirror scan now applies in a single-byte locale whenever the text holds a non-ASCII character (decoded_unit_len is 1 byte/unit there); pure ASCII keeps the historical character scan. - slurped_record_eof_no_delimiter: the EOF verdict walk now charges ch.len_utf8() per unit in a single-byte locale, so a budget-satisfied read over a short input reports rc 0, not EOF. - truncate_read_post_escape: the slurp cut now always runs in the decoded byte domain in a single-byte locale, so a cut may land mid-character (dangling lead byte rides a raw-byte marker). No change in a multibyte locale. Regression nails: tests/issue3785_read_n_bytes_redirect_pipeline.rs (20 tests). * test: pin UTF-8 locale in #714 multibyte nail (Refs #3785) The #714 nail read_n_multibyte_char_count_unchanged asserts multibyte counting but never pinned the locale, so it ran under whatever locale the test process carried. rubash#3785 made -n count bytes in a single-byte locale (GNU read.def:851,874), so under LC_ALL=C the same -n 2 over e-acute + Z takes just the two bytes of e-acute and the nail fails. Pin LC_ALL=C.utf8 so the nail asserts what its name claims on every machine. --------- Co-authored-by: 曹梦轩 <[email protected]>
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.
根因
StdinCharDecoder::next_unit(src/executor/read_helpers.rs)的单字节分支在!is_multi_byte()时仍把合法 UTF-8 序列聚成一个Char单位,于是 LC_ALL=C 下read -n 1读到é(c3 a9)时一次取走两个字节,-n 2取走é+x。GNU 锚点
mb_cur_max > 1时调用read_mbchar分组多字节字符;MB_CUR_MAX == 1 时不分组。nr++按单位计,if (nchars > 0 && nr >= nchars) break;—— 单字节 locale 下每字节一个单位。zreadn (fd, &c, nchars - nr)(-N 面同预算)。改动
StdinCharDecoder::next_unit单字节分支:一字节一单位(ASCII 仍为Char,高位字节走RawByte单位,其 marker 文本原样重发该字节;stdin_unit_is_delimiter对两种单位都按首字节比较,结果一致)。多字节分支未动。两个字节循环调用方(read_inherited_process_stdin、read_stdin_until)对两种单位对称处理,计数/回显/转义逻辑不变。scripts/check-utf8-boundary-hygiene.sh增加 allowlist 条目:byte as char仅出现在if byte < 0x80分支(else 分支把 >= 0x80 交给raw_byte_unit),与既有read_split.rs条目同理。本 PR 删除了什么
无。仅替换单字节分支的单位划分逻辑;无公开面、无文件、无功能删除。
未验项
UNVERIFIED-BY-CAPTAIN:本轮无任何构建/测试腿可用(本地构建禁令、Simular box 盘满、老服务器 ssh 未恢复、X299 腿留复核轮),未跑
cargo test、未跑RUSTFLAGS="-D warnings" cargo check、未跑全量 lib 对比。仅做过:rustfmt --check(两处改动文件通过)、check-utf8-boundary-hygiene.sh(clean)、check-marker-literals.py(OK)。新钉为 fail-first 设计(在修前 master 上 6 例 C-locale 断言应失败,待复核轮跑钉验证)。队长注意(同文件面残差,未动)
read_function_stdin的scan_record(src/executor/read_io.rs,FUNCTION_STDIN 镜像按字面字符计单位)在 C locale 下对字面é同样多计,且该文件在飞 PR fix(executor): termsig death during comsub, blocking read and simulated-exec waits (Refs #3401) #3455 有三处 hunk,按护栏未碰;② slurp/trim 路径的字符计数(truncate_read_post_escape文本走查、slurped_record_eof_no_delimiter)在 C locale 下对字面多字节字符同样按字符计——修这两处会动tests/issue714_read_limit_transport_units.rs的read_n_multibyte_char_count_unchanged(该测试未定 locale,默认 C locale 下锁定了字符计数,须先将其钉到 C.UTF-8 再改)。建议队长裁定:① 等 fix(executor): termsig death during comsub, blocking read and simulated-exec waits (Refs #3401) #3455 合入后另立案修镜像扫描,② 另立案修 slurp/trim 面并同步重钉 read -n/-N: limit counts transport units, splitting the last kept carrier pair #714。