Closed
PyACL 字典标量转换静默窄化 #1188
KaranocaVeAdd on Oct 21Closed at 24 days ago
Oct 21 Associated pull request
Oct 21 Modify description of issue
Oct 21 Assign yongfei-hu as responsible person
Oct 21 Removed responsible person yongfei-hu
wuqifan
Oct 21 Comments:
Oct 21 Comments:
/assign


Oct 21 Assign weixin_46600764 as responsible person
wuqifan
Oct 21 Comments:
Oct 21 Comments:
感谢反馈!您所提的pyACL接口问题已收到,根据提供的信息核实:GetValueFromPyDict 的 int 与 short 两条转换路径确实存在窄化前未做范围检查的问题,超范围取值会被静默截断。我们正在验证该问题,由于该接口在多处被调用,修复会在通过测试后合入。


wuqifan
26 days ago Comments:
26 days ago Comments:
您好,感谢反馈!
已对该问题及 MR !5715 进行了修复前后对照。原实现确实会在检查 Python 异常前将 long 窄化为目标类型;当输入超出目标类型范围但仍可由 long 表示时,值可能被静默改变。以 int 路径为例,修复前通过 acl.rt.binary_load_from_file 传入 2**32,底层调用观察到的值为 0;MR 版本返回 ValueError,且未进入底层调用。short helper 对 32768 的对照结果也由修复前的 -32768 变为 ValueError。正常值及类型边界值的对照通过。我们会尽快推进合入,感谢贡献修复!


ykl999
24 days ago Comments:
24 days ago Comments:
pr已合入,issue关闭处理


24 days ago changed custom state from 进行中 to 已解决
24 days ago Close issue
24 days ago Added label: resolved
PyACL 字典标量转换静默窄化
现象
Runtime 的 Python binding 通用
GetValueFromPyDict在int和short标量路径中先将 Python 整数直接窄化,再检查PyErr_Occurred()。在 64 位平台,PyLong_AsLong可成功表示但超出目标字段范围的值(如2**32、32768)会被静默截断,调用方收到与输入不同的配置。影响
多个 pyACL 配置接口共用该 helper。错误的枚举、计数或短整数字段可能被改写后继续调用底层 ACL,导致配置失真且缺少输入错误提示。
根因与修复
保留
long中间值,在赋给int/short前分别检查INT_MIN..INT_MAX与SHRT_MIN..SHRT_MAX,超范围返回ValueError。验证
static_cast<int>(PyLong_AsLong(...))和static_cast<short>(PyLong_AsLong(...)),窄化发生在错误检查前。git diff --check通过。master的93b7ec22运行目标仓库 pre-commit(clang-format v16.0.0、OAT),python/pyACL/utils_methods.cpp检查通过。关联 PR: https://gitcode.com/cann/runtime/merge_requests/5715