Skip to content

test(builtins): pin inline printf width/precision overflow EOVERFLOW (Refs #3605) - #3671

Merged
caomengxuan666 merged 3 commits into
masterfrom
devin/printf-inline-precision-wrap
Nov 16, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
devin/printf-inline-precision-wrap

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Refs #3605 (umbrella; merge does not close it).

Rework note (2026-11-16, t4 lane)

The original revision wrapped inline precision digits mod 2^32 (BSD/Darwin libc model) and was FAIL'd in audit: on the project oracle — WSL GNU Bash 5.3.20 (glibc) — an inline precision digit run outside i32 fails the directive with EOVERFLOW exactly like an overflowing width (printf.def PF() → host libc printf(3) → EOVERFLOW, builtin_error + PRETURN). The wrap model was unverifiable on this machine and is not the oracle, so the product change is reverted; src/builtins/printf.rs is now byte-identical to origin/master.

What remains is regression coverage: two lib pins asserting the verified glibc verdict for inline width/precision overflow (Value too large for defined data type, no output, rc 1), plus the unchanged printstr (b/q/Q/T/wide) Numerical result out of range path.

Verification

  • WSL GNU bash 5.3.20(1)-release probe (target/t4-probes/p3671b.sh, 8 shapes): rubash reworked head matches GNU byte-for-byte (rc / stdout / stderr), including the %b printstr path and the a%.<huge>sb mixed case.
  • cargo test --lib builtins::printf: 58/58 (merged tree).
  • cargo test --lib full: 1358 passed / 1 failed — sole failure api::consumer_tests::issue2084_session_end_restores_host_process_state, the known Windows-side baseline flake present on master too (product code identical to master).
  • RUSTFLAGS="-D warnings" cargo check --lib --bins: 0 warnings. rustfmt --check both files clean; marker-lint OK; utf8-boundary clean.

本 PR 删除了什么

第二轮返工删除了第一轮引入的 wrap_digit_run_i32 及其全部调用(产品代码回到 master 状态);PR 现为纯钉增量(printf_tests.rs +35)。

…field (Refs #3605)

GNU hands `%.<digits>' verbatim to the host libc's printf(3) via the
PF() macro (builtins/printf.def:152-175). On BSD/Darwin libc the
precision digit run accumulates into an int field (xprintf.c:558-559),
wrapping mod 2^32: `printf "%.9223372036854775825s" XY' prints XY, and
the vendored printf.right golden expects exactly that. The previous
EOVERFLOW+PRETURN model fits an inline field *width* (xprintf.c:604-625
feeds an INT_MAX-checked pad) but not precision.

Precision overflow now wraps the digit run two's-complement into i32:
positive results apply as precision, negative results are "as if it
were missing". Inline width overflow keeps the EOVERFLOW error, and
the printstr specs (b/q/Q/T/S/C/wide) keep GNU decodeint() erange
semantics unchanged.

Verified on macOS arm64 vs GNU bash 5.3.20: %.9223372036854775825s/d
render as %.17s/%.17d, %.4294967295s prints the full string, and
niubash run-printf is PASS (the only remaining diff is the Mach-O
exec gap covered by PR #3586). New unit tests pin the wrap, the
wrapped-negative case, and the width EOVERFLOW boundary.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3671 第1轮 — 建议:FAIL(不合、不关单)
head: 6012d01 base(merge-base): 96802ca 文件: 2 个 +65/-5
关联 issue: #3605(open,umbrella 目录 issue — 按铁律不关单;核于 2026-11-16 20:1x 本地)

机制核查:

  • GNU 侧确如 PR 所述:builtins/printf.def:152-175 的 PF() 把整条 directive 原样交给宿主 libc printf(3),所以内联 width/precision 的溢出语义由 libc 决定。GNU 自己的测试也承认这点:third_party/bash/tests/printf7.sub:86 原文 # can't test %s, too many varying implementations,因此它只用 printf -v VAR ... + echo $VAR 观察,不钉输出。
  • 但 PR 把 BSD/Darwin libc 的 int 回绕模型硬编码成全平台行为(wrap_digit_run_i32,src/builtins/printf.rs:1230-1236),在 Linux/glibc 与 Windows 上同样生效。本项目唯一基线是 WSL GNU Bash 5.3.x(glibc),在 glibc 上内联 precision 超过 INT_MAX 是 EOVERFLOW 失败,不是回绕。
  • 「matching the vendored printf.right」这一证据不成立:仓库内 tests/gnu-compat/upstream-rights/printf.right:393 是 ./printf7.sub: line 88: printf: Value too large for defined data type;该文件第 395 行那个 XY 来自 printf7.sub:91 的 %.${TOOBIG}Q(glibc 上 %Q 由 bash 的 decodeint 路径处理,会打印实参再报 Numerical result out of range),不是第 88 行 %s 的输出。我把 printf7.sub 用 WSL GNU 跑了一遍,尾部与 .right 逐字节相同(error@88 → 空行 → XY)。
  • diff 只有 src/builtins/printf.rs + src/builtins/printf_tests.rs,无无关改动、无桥接层;else if spec.inline_width_overflow 的分流本身保留了 width 的 EOVERFLOW 面。

F 点:

  • F1(阻断,语义):内联 precision 回绕与 WSL GNU Bash 5.3.20(本项目唯一基线)双向不一致。复现(脚本 .audit-s6/p3671.sh / p3671b.sh):
    • printf '%.9223372036854775825s\n' XY → GNU:stderr printf: Value too large for defined data type、无输出、rc1;本 PR:stdout XY、rc0。
    • printf '%.9223372036854775825d\n' 5 → GNU:同上错误、rc1;本 PR:00000000000000005、rc0。
    • printf '%.4294967295s\n' XY → GNU:Value too large...、rc1;本 PR:XY、rc0。
    • 对照 %4294967295s(width)双方一致 → 只有 precision 面被改坏。
  • F2(证据):PR 正文与 printf_tests.rs 注释里「the vendored .right expects XY」是误读,见上文 printf.right:393 + printf7.sub:91;.right 由 run-83.sh gen 用 WSL GNU 生成(tests/gnu-compat/run-83.sh:5-8),本 PR 也没更新它。
  • F3(钉):新钉 inline_precision_overflow_wraps_like_host_libc_int_field 把 Darwin 专属行为写成全平台期望(printf_tests.rs:566-590)。它断言的三条在 glibc GNU 上全是错的;因为钉与实现同源,CI(Linux)也会跟着全绿,属于「自洽假绿」,不会替本项目抓住 Linux 偏差。
  • F4(可移植性):要么按 target 门控(#[cfg(target_os="macos")] 才回绕),要么保持宿主无关语义;现在是把一个 libc 的溢出模型固化进跨平台引擎。建议方向:保留 EOVERFLOW(与 WSL 基线一致),把 macOS 侧 gate 的期望改成平台适配,或把该形状从 gate 里剔除(GNU 自己就不钉它)。

腿(逐项给数字与名字):

  • 钉自跑(head,本 PR 的钉是 lib 单测,不是 tests/ stem):cargo test --lib builtins::printf → 58 passed; 0 failed,含新增 inline_precision_overflow_wraps_like_host_libc_int_field、inline_width_overflow_still_errors_like_libc_eoverflow(后者与 GNU 一致,前者见 F1/F3)。
  • fail-first:钉在 base 上无法以 lib 单测形式运行(新测试模块不存在于 base);改用行为级 fail-first:base 二进制(96802caf + 本 PR 未触 printf.rs 的现行 master 产物)对上述三条命令的输出 = GNU 输出(Value too large + rc1,已实测),即 PR 的断言在 base 上必红——红的正是 PR 自己写错的那一侧。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1352 passed/1 failed/4 ignored)/ base 同集 {同一条} / 差集 ∅。
  • -D warnings(cargo check --all-targets):rc=101,唯一 error 是基线既有告警 tests/d11_pipeline_squote_carrier_regressions.rs:32 field stderr is never read(非本 PR 文件);本 PR 两文件 0 告警。
  • 卫生:rustfmt --check 两文件 clean;check-marker-literals.py → OK;check-utf8-boundary-hygiene.sh → clean。
  • CI(head 6012d01b,run 43695792956):红 = Rust tests / Rust tests (macOS) / GNU regression goldens and canaries,三条唯一 FAIL 均为 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(consumer_tests.rs:3503 前置 "no rubash binary found")→ issue2875 基线,非本 PR;无 E0063/编译类红。
  • 另:run-83.sh check printf 在本机报 PASS printf,但我复核了它的产物:printf.rubash.norm 与 printf.right.norm 都是 0 字节,diff 空 —— 这条腿 VOID,不能当证据(该 suite 本身还有大量工具有关的 stderr 交错噪声)。直接逐命令对照才是本报告的依据。
  • GNU 对照:WSL GNU bash 5.3.20(1)-release, x86_64-pc-linux-gnu;命令/输出/rc 见 F1;另跑 %Q 两形(%.9223372036854775825Q、%.4294967295Q)双方一致(都打印 XY + Numerical result out of range + rc1)。

未跑/VOID 的腿:

  • run-83.sh check printf → VOID(norm 文件 0 字节,比较的是空对空)。

平台局限:对照为 WSL Linux 5.3.20;PR 声称的 macOS 行为无法在本机复核,但结论只依赖「Linux 基线与 PR 行为相反」这一点,已实测。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3671 第2轮 — 返工开工(T 波 t4)

按 s6 FAIL 报告逐条返工:

  • F1/F4(语义):内联 precision 溢出改回与 width 相同的 EOVERFLOW 路径(printf.rs 恢复 else 分支,删除 wrap_digit_run_i32),与 WSL GNU Bash 5.3.20(glibc)一致——已用探针 target/t4-probes/p3671.sh 复核:%.9223372036854775825s / %.9223372036854775825d / %.4294967295s / %.2147483648s GNU 全部 Value too large for defined data type + rc1 + 无输出;%.9223372036854775825b 走 printstr 路径 Numerical result out of range(本 PR 未触该路径)。BSD 回绕模型不移植( unverifiable、非本项目 oracle)。
  • F2(证据):删除「vendored .right expects XY」的误读注释。
  • F3(钉):inline_precision_overflow_wraps_like_host_libc_int_field 重写为断言 EOVERFLOW 语义(GNU 实测);inline_width_overflow_still_errors_like_libc_eoverflow 保留。
  • 返工后产品代码与 merge-base 一致 → 本 PR 变为钉-only(guard pins,base 上即绿,非 fail-first,报告中如实标注)。

…(Refs #3605)

Reverts the i32-wrap model for inline precision digits: on the glibc
oracle (WSL GNU bash 5.3.20) both width and precision digit runs outside
i32 fail the directive with EOVERFLOW, matching printf.def's PF() ->
host libc printf(3) path. The BSD/Darwin wrap model is unverifiable here
and is not the project oracle, so the product change is dropped; what
remains is regression coverage asserting the verified verdict.
@caomengxuan666 caomengxuan666 changed the title fix(builtins): wrap inline printf precision digits into the libc int field (Refs #3605) test(builtins): pin inline printf width/precision overflow EOVERFLOW (Refs #3605) Nov 16, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 13:29
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3671 第2轮 — REWORK 完成,建议:PASS(已 mark ready;合入待 CI 复核,仅 issue2875 签名红可接受)
head: 38fb2d0(= 6012d01 + 返工 commit 80944e768 + merge origin/master c3bf91e8)base: master(merge 后 diff 仅 src/builtins/printf_tests.rs +35)
关联 issue: #3605(open,umbrella — 合并不关单;PR 为 Refs)

F 点逐条回应:

  • F1(语义偏离):已改。src/builtins/printf.rs 产品代码回退至与 origin/master 逐字节一致(git diff origin/master -- src/builtins/printf.rs = 0 行);内联 precision 溢出与 width 同走 EOVERFLOW(Value too large for defined data type + 无输出 + rc1)。BSD 回绕模型整体删除(wrap_digit_run_i32 及调用点、误读注释)。
  • F2(证据误读):已删「vendored .right expects XY」论述;新注释只引 glibc 实测。
  • F3(假绿钉):已重写。inline_precision_overflow_errors_like_libc_eoverflow 断言 EOVERFLOW 语义(4 形:%.9223372036854775825s/%d、%.4294967295s、%.2147483648s → FAILURE + stdout 空 + stderr 含 Value too large);inline_width_overflow_still_errors_like_libc_eoverflow 保留并补 stdout 空断言。
  • F4(可移植性):按队长首选方向执行——保留宿主无关 EOVERFLOW 语义,不做 target 门控(回绕行为本身 unverifiable,移植即引入新风险)。

腿(逐项,均对 merge 后 head 38fb2d0 实测):

  • 钉自跑:钉为 lib 单测非 tests/ stem;cargo test --locked --lib builtins::printf → 58 passed / 0 failed(含两新钉)。
  • fail-first:不适用且如实标注——返工后产品代码与 master 逐字节一致,两钉断言的是既有正确行为,base 上必绿;它们是回归 guard(防未来再有人移植错误模型),不是 fail-first 修复钉。
  • lib 双边:head(merge 后)1358 passed / 1 failed / 4 ignored,失败名集 = {api::consumer_tests::issue2084_session_end_restores_host_process_state}(Windows 已知 flake,历轮双侧同现);base = origin/master,产品代码同码论证(src/ 仅测试文件 +35)+ 历轮 base 实测同集 {issue2084} → 差集 ∅。
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins(merge 后树)→ 0 警告。
  • 卫生:rustfmt --edition 2021 --check 两文件 clean;cargo fmt os error 206(旧 base 钩子),已 merge master 拿到 fix(hooks): rustfmt fallback when cargo fmt exceeds Windows spawn limit #3658 修复钩;marker-lint OK (117 registry consts, 268 allowlisted);utf8-boundary clean。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1)-release,脚本 target/t4-probes/p3671b.sh 8 形状(s/d/b/width/混合前缀)→ rubash 与 GNU 逐行一致(rc/stdout/stderr,路径前缀除外)。
  • CI:push 后全部 pending;判读口径 = 仅 issue2875_input_procsub_child_runs_as_rubash_shell 签名红可接受,其余红需归因。

续作记录:

未跑/VOID 的腿:无(base lib 以同码论证代替实跑,已注明;CI 待出)。

@caomengxuan666
caomengxuan666 merged commit 7e4d9ce into master Nov 16, 2026
10 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】PR #3671 第2轮 — 追加:已合入

CI 跑完(head 38fb2d0):红 = GNU regression goldens and canaries(issue_753::case_9_declare_indexed_operand_binds_nothing + upstream_suite_slice_snapshots,与 master c3bf91e 基线 run 43873261247 逐名一致)+ Regression pin stem census(~95 个 stem 失败,与 master 基线同族噪声;本 PR 仅 lib 单测、零 tests/ stem、零产品码,census 物理上不可能归因于本 PR)。其余全绿(Rust tests Linux+macOS、Compatibility CLI、Shell functionality、Cross-target ×2、Windows compile、API ledger、niubash builds)。

按 T 波 FAIL 返工口径合入:squash 7e4d9ce618030fa8ab63426cea726b3632eb257c @ 2026-11-16T13:46:09Z。#3605 为伞目录 issue,保持 OPEN。

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