Closed
pyACL 字典整数参数的无符号窄化 #1352
KaranocaVeAdd on 19 days agoClosed at 16 hours ago
19 days ago Associated pull request
19 days ago Modify description of issue
duanpengliang
19 days ago Comments:
19 days ago Comments:
初步分析,pyACL 字典转换缺少目标无符号类型的上界检查。当整数超出目标类型范围、但仍处于 unsigned long 范围内时,转换函数会返回成功并传递截断后的值,造成配置值与底层参数不一致;已有 int/short 修复未覆盖这些路径。
该问题已有关联 PR:https://gitcode.com/cann/runtime/merge_requests/6199。后续需核对窄化前的范围检查及标量、数组边界回归,确保越界输入报错、合法值保持原值。


19 days ago Assign KaranocaVe、xiao_cun as responsible person
17 days ago Associated pull request
wuqifan
17 days ago Comments:
17 days ago Comments:
感谢反馈!已对关联 MR !6199 进行源码核查和修复前后验证,比较版本为 506b16123480 → 190d3877cc30。在 Linux aarch64、CANN 9.3、Python 3.9.9 环境下,分别完整构建两版 pyACL,通过真实 Python 接口验证了三种无符号标量和两种数组转换路径。基线会截断越界值并继续调用底层;MR 版本在所测路径上抛出 ValueError,且不再调用底层。每版 48 个用例均符合预期。此外,由于我们当前的测试用例暂未开源,请从本 MR 中移除新增的 tests/ut/pyACL/test_utils_unsigned_range.cpp,保留修复代码即可。感谢修复,我们会尽快推进合入!


9 days ago Assign weixin_46600764 as responsible person
2 days ago Associated pull request
ykl999
16 hours ago Comments:
16 hours ago Comments:
你好,pr已上库,相关pyacl的问题已修改,感谢贡献!


16 hours ago changed custom state from 待办的 to 已解决
16 hours ago Close issue
13 hours ago Added label: resolved
pyACL 字典整数参数的无符号窄化
现象
固定源码
cann/runtime@506b161234801758c070c873da1c5d6e07c663b8的 pyACL 字典转换 helper 在将 Python 整数写入unsigned char、unsigned short、unsigned int及对应数组时,先把PyLong_AsUnsignedLong的结果静默转换为目标窄类型。64 位 Host 上,超出目标类型范围的值因此回绕后继续传给 ACL。证据
python/pyACL/utils_methods.cpp的三个无符号标量转换和两个无符号数组转换均在范围检查前执行窄化;基线探针传入USHRT_MAX + 1时 helper 返回成功,输出值已被截断。int/short有符号范围修复只覆盖对应有符号重载;本案针对仍未校验的无符号重载和数组路径,范围独立。unsigned short、unsigned int、unsigned char以及hi_u8[]、unsigned int[]的越界值,最终补丁均返回ValueError。影响
Python 配置值与底层 ACL 实际收到的值可能不一致。调用者无法从返回状态判断发生了截断,设备配置、媒体参数和保留字段等使用这些 helper 的接口都可能受到影响。
修复
保留
PyLong_AsUnsignedLong的宽类型结果,在转换为目标类型前分别检查UCHAR_MAX、USHRT_MAX和UINT_MAX;越界统一设置ValueError并拒绝调用者输入。新增 CPython helper 回归测试覆盖标量与数组路径。验证
g++ -std=c++17 -Wall -Wextra -Werror -fsyntax-only对 helper 和回归测试通过;clang-format --dry-run --Werror、git diff --check通过。git apply --check --whitespace=error-all fix.patch在固定源码 checkout 上通过。关联 PR: https://gitcode.com/cann/runtime/merge_requests/6199