UB: (int) cast of a user double outside int range in dispatch / vm_index_is_int / flat_index_at
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从指定的四个位置开始:src/builtins.c 约第 5946 行的 builtin_dispatch、src/vm.c 中的 vm_index_is_int、src/builtins_tensor.c 中 flat_index_at 的列表分支,以及 finite_num_to_byte。在 make asan 下使用 issue 中的分发代码片段复现,查看 UBSan 的 float-cast-overflow 报告。完成标准为:每个位置在强制转换前对 double 做范围检查(NaN 判为假);grep -n '(int)' src/*.c 的结果已完成分类;复现程序输出 value 错误,且不再出现任何 runtime error: 行。
由索引模型根据 Issue 内容生成。
描述
Found while building #1746 Phase 1. Several sites convert a user double to int with a bare (int) cast before any range check. For |x| >= 2^31 (today: up to ±1e308; under an IEEE build also inf/NaN) that is undefined behaviour, and UBSan's float-cast-overflow (on in every ASan variant) reports it.
Repro (any asan build):
define g(x) as:
return x
d is dispatch
print of (d of [[g], 1e308, 5])
-> src/builtins.c:5946:20: runtime error: 1e+308 is outside the range of representable values of type 'int' (then the intended dispatch key must be an integer raise).
Sites: builtin_dispatch (builtins.c, (int)eigs_num_arg(key_v, ...)), vm_index_is_int (vm.c), flat_index_at list arm (builtins_tensor.c), finite_num_to_byte ((int)fmod(x,256) with a NaN). The #1746 experiment guards only vm_index_is_int, only under -DEIGS_IEEE.
Done when
- Each listed site range-checks (
!(d >= INT_MIN && d <= INT_MAX)style, NaN-false) before the cast, and the sweepgrep -n '(int)' src/*.cover user-double conversions is classified. - The repro above is clean under
make asan(noruntime error:), and still raisesvalue.
- 主要语言
- C
- 星标
- 3
- 派生
- 7
- 平均合并
- 11 小时 45 分钟
- 30 天内合并 PR
- 273
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
InauguralSystems/EigenScript 的其他 Issue
-
area:docs kind:docs-drift
难度 2/5 1-3 小时 新手友好度 76/100
InauguralSystems/EigenScript#1887 ·
维护者通常 1 天内回复
-
area:stdlib kind:silent-wrong
难度 2/5 1-3 小时 新手友好度 88/100
InauguralSystems/EigenScript#1878 ·
维护者通常 1 天内回复
-
area:gates kind:docs-drift
难度 1/5 1 小时以内 新手友好度 86/100
InauguralSystems/EigenScript#1851 ·
维护者通常 1 天内回复
-
area:gates area:gfx found-by:critic kind:gate-defect
难度 2/5 1-3 小时 新手友好度 78/100
InauguralSystems/EigenScript#1825 ·
维护者通常 1 天内回复
-
area:gfx bug
难度 2/5 1-3 小时 新手友好度 66/100
InauguralSystems/EigenScript#1684 ·
维护者通常 1 天内回复
查看 InauguralSystems/EigenScript 的全部 Issue
相似的 Issue
-
v9.6.0: CMake incorrectly enforces presence of libevdev可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
bug Component component: net
难度 2/5 1-3 小时 新手友好度 78/100
RT-Thread/rt-thread#11913 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
contiki-ng/contiki-ng#3289 ·
维护者通常 3 天内回复
-
area:docs help wanted type:enhancement
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复