Repository navigation
fix(executor): count bytes for read -n/-N in single-byte locale (Refs #3785) - #3810
Merged
Merged
Conversation
…tdin (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).
…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).
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.
Member
Author
|
【Y3-AUDIT】PR #3810 第1轮 — 建议:PASS 机制核查:
腿:
F 点:无 未跑/VOID 的腿:无 |
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.
根因
在单字节 locale(
LC_ALL=C)下,GNUread -n N/-N N按字节计数(builtins/read.def:851,874,880-886:仅当mb_cur_max > 1才调read_mbchar;否则每字节一个单位,nr++)。#3477(Refs #3334)只修了继承 stdin 的StdinCharDecoder;其余三处 serve 仍按字符计数:< file/0<file/<<</ heredoc):trim_read_input→truncate_read_post_escape的无 marker 走查数chars();slurped_record_eof_no_delimiter的 EOF 判定同法计数,导致预算满足的短输入误报 EOF(rc 1)。read_function_stdin的 FUNCTION_STDIN 镜像):byte_unit_scan_applies只在多字节 locale 且含 raw-byte marker 时才走字节域扫描。修复(三处机制改动,均在
src/executor/read_helpers.rs)byte_unit_scan_applies:单字节 locale 下镜像文本含非 ASCII 字符即走字节域扫描scan_text_record_bytes;纯 ASCII 保持旧字符扫描。slurped_record_eof_no_delimiter:单字节下单位代价为ch.len_utf8(),与截断侧的字节域计数一致。truncate_read_post_escape:单字节下无条件走解码字节域截断,切口可落在字符中间(悬空首字节以 raw-byte marker 承载)。多字节 locale 行为不变。
回归钉
tests/issue3785_read_n_bytes_redirect_pipeline.rs(20 格):< file、-N < file、-n 1、0<file、EOF rc、<<<(-n/-N)、管道 brace/parens/function(-n 与 -N)、连续-n 1读、管道 EOF rc、< /dev/stdin,及对照(继承 stdin、组重定向、C.utf8 字符计数、ASCII、plain read)。tests/issue714_read_limit_transport_units.rs:read_n_multibyte_char_count_unchanged钉死LC_ALL=C.utf8——该钉断言多字节计数,本修法后在单字节 locale 下同一-n 2只取é的两字节,钉的期望仅在 UTF-8 locale 下成立;此前它随测试进程的环境 locale 漂移。验证(X299-2607,Windows MSVC,基底 5f32a7c)
api::consumer_tests::issue2084_session_end_restores_host_process_state(基底同红,与本修法无关)。RUSTFLAGS="-D warnings" cargo check --locked --lib --bins:零警告,rc 0。rustfmt --check(三文件):干净,rc 0。本 PR 删除了什么
无。仅新增测试文件与一处既有测试的 locale 钉死;产品代码为三处计数域改动,无删除、无公开面变化(未碰
docs/api-ledger.md,未碰src/lexer/continuation.rs)。UNVERIFIED-BY-CAPTAIN