Pull Request has been successfully merged by CANN-robot.
(Thank you for KaranocaVe's contribution.)变更摘要
本 PR 针对 python/pyACL/util/bytes_convert.cpp 中 WrapPtrToBytes 的函数行为进行修正:在将指针转换为 bytes 对象前,新增对空指针参数的校验。此前空地址会被直接传入 PyBytes_FromStringAndSize,CPython 会据此创建内容未定义的 bytes 对象,导致 acl.util.ptr_to_bytes(0, size) 在 size > 0 时返回内容不确定的对象。本次改动在转换前拒绝「空地址且长度非零」的入参,同时保留零长度转换允许空地址的行为。
主要改动
- 新增空指针参数校验: 在
WrapPtrToBytes中解析args之后、调用PyBytes_FromStringAndSize之前,插入CHECK_NULL(ptr != nullptr || size == 0, ...),对空地址且长度非零的入参进行拦截。 - 明确零长度转换的边界条件: 校验条件
size == 0使得空地址在零长度场景下仍然合法,维持原有零长度转换可用。 - 统一错误类型为
PyExc_ValueError: 校验失败时以PyExc_ValueError上报错误信息ptr must not be null when size is nonzero,与同函数中后续转换失败的异常类型保持一致。
🧩 本次 Review 已使用自定义 Skill:




Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.
For more, you also can visit HICANN.
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/runtime | ✅ 卢煜坤, yanmingxiang (2/2) | ✅ 卢煜坤 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
KaranocaVe, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/compile


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


按机器人当前审批进度,模块 repo-cann/runtime 还缺 approve。麻烦 @yanmingxiang @Reyn52166 @houyanbao @ykl999 @wangtao43 抽空协助审批,并在条件满足后推进合并,谢谢!


再跟进一下:按机器人最新审批进度,模块 repo-cann/runtime 仍待 approve。麻烦 @yanmingxiang @Reyn52166 @houyanbao @ykl999 @wangtao43 再次抽空协助审批,并在审批条件满足后推进合并,谢谢!


/compile


/compile


/approve
/lgtm


| 🚀 CI 流水线已启动 |
|---|
| 📋 执行详情: 点击查看流水线 |


/lgtm


fix(runtime): 校验 acl.util.ptr_to_bytes 空指针参数
WrapPtrToBytes将空指针传给PyBytes_FromStringAndSize。CPython 将该调用解释为创建未初始化内容的 bytes 对象,因此acl.util.ptr_to_bytes(0, size)在size > 0时会返回内容未定义的对象。在转换前拒绝“空地址且长度非零”,并在 Python API 文档中补充参数约束。零长度转换仍允许空地址。
使用 Python 3.11 的 CPython C API 做了有效地址和空地址对照;空地址加正长度返回指定长度的 bytes 对象。补丁检查通过;未编译完整扩展或执行设备测试。
关联 Issue: https://gitcode.com/cann/runtime/issues/1170