Closed
Runtime Python group 属性返回长度单位错误 #1162
KaranocaVeAdd on  Oct 20Closed at  23 days ago
KaranocaVe
KaranocaVe
Oct 20 Create

Runtime Python group 属性返回长度单位错误

现象

acl.rt.get_group_info_detail 调用 C API 后,将 paramRetRize 直接传给 PyList_New,并按同一数值遍历 attrValue。但 aclrtGetGroupInfoDetail 的输出长度是字节数。当前六种 aclrtGroupAttr 均对应单个整数属性;实现通过 sizeof(字段) 拷贝并把该字节数写入 paramRetSize。在常见的 32 位 int32_t 属性上,API 返回 4,Python 包装层因此构造 4 个列表元素,而 C API 只写入第一个元素。

影响

调用者得到的列表长度和属性值不符,尾部三个元素来自未由 C API 初始化的局部数组内容,值不确定,并可能暴露该栈区域的旧数据。合法成功调用会产生错误结果。

依据

  • python/pyACL/rt/pyrt_methods.cpp 注册公开方法 get_group_info_detail。
  • python/pyACL/rt/rt_group.cpp 将 C API 输出的 paramRetRize 作为列表长度和元素循环上界。
  • src/acl/aclrt_impl/group.cpp 的 FillAttrValue 用 memcpy_s 复制属性,并令 *paramRetSize = srcLen;各属性分支传入对应字段的 sizeof。
  • include/external/acl/acl_rt.h 将 paramRetSize 定义为属性值的实际长度,参数类型为 size_t*,输出缓冲区为字节指针。

修复

校验返回字节数能被 sizeof(attrValue[0]) 整除,再按字节数除以元素大小计算 Python 列表长度及遍历次数。修复只调整 Python 包装层,不改变 C API。

关联 PR: https://gitcode.com/cann/runtime/merge_requests/5682

likedislike
KaranocaVeKaranocaVe
Oct 20 Associated pull request
KaranocaVeKaranocaVe
Oct 20 Modify description of issue
nevermore
nevermoreCollaborators
Oct 20 Comments:

您好,感谢反馈。我们已关注该问题,正在结合代码实现进一步核查。后续确认问题原因和影响范围后,会在本 Issue 中同步分析结论及处理方案。

likedislike
nevermorenevermoreCollaborators
Oct 20 Assign nevermore_t as responsible person
wuqifan
wuqifan
26 days ago Comments:

您好,相关 pyACL 问题已经确认。aclrtGetGroupInfoDetail 返回的 paramRetSize 表示属性值的字节数,当前 Python 包装层将其直接作为列表元素数量,导致返回列表包含多余的未初始化元素。相关 MR !5682 增加了返回长度的整除校验,并将字节数换算为元素个数后再创建和遍历列表,修改方向合理,可以修复该问题。我们会继续推进相关 MR 的检视和合入,感谢反馈和贡献!

likedislike
ykl999ykl999Collaborators
23 days ago changed custom state from 进行中 to 已解决
ykl999ykl999Collaborators
23 days ago Close issue
ykl999
ykl999Collaborators
23 days ago Comments:

pr已合入,感谢贡献!

likedislike
CANN-robotCANN-robotCollaborators
23 days ago Added label: resolved