Merged
fix: 校验 PyACL 批量 VPC ROI 数组长度 #5681
fix: 校验 PyACL 批量 VPC ROI 数组长度 #5681
Merged
KaranocaVeAdd on Oct 20
KaranocaVe
Oct 20

fix: 校验 PyACL 批量 VPC ROI 数组长度

批量 VPC crop 包装器按 roiNums 中的数量把 cropAreas 传给 C API,但未校验两者是否匹配。例如 roiNums=[3]、cropAreas 只有一项时,C API 仍会按计数读取三项,可能造成越界读取、进程崩溃或未定义行为。预期是在调用 C API 前拒绝长度不匹配的输入。
修复在批量 crop、crop-and-paste、crop-resize、crop-resize-paste 和 crop-resize-make-border 包装器中检查 ROI 数量总和与 cropAreas 长度,并检查 paste/border 配对数组长度。Host AddressSanitizer 探针在基线版本复现越界读取;修复后不匹配输入在进入 C API 前抛出 ValueError,匹配输入仍成功。探针使用 API stub,未调用真实 NPU DVPP API。

关联 Issue: https://gitcode.com/cann/runtime/issues/1161

likedislike
Pull Request has been successfully merged by CANN-robot.
(Thank you for KaranocaVe's contribution.)
KaranocaVeKaranocaVe
Oct 20 Created pull request, commit 73af28b4
KaranocaVeKaranocaVe
Oct 20 Associated issue: PyACL 批量 VPC crop 的 ROI 长度不匹配会越界读取
atomgit-bot
atomgit-bot
Oct 20 Comments:

变更摘要

本次变更聚焦于 python/pyACL/media/media_vpc.cpp 中 PyACL 批量 VPC 相关包装器的输入校验。此前这些包装器按 roiNums 的数量将 cropAreas 传递给 C API,但未验证两者是否匹配,可能导致 C API 按计数越界读取。修复新增了静态辅助函数 CheckBatchRoiArrayLength,在进入 C API 前比对 ROI 数量总和与 ROI 数组长度,不匹配时抛出 ValueError,并在各批量包装器中接入该检查及补充 paste/border 配对数组的长度校验。

主要改动

  • 新增 ROI 长度校验辅助函数: 新增 CheckBatchRoiArrayLength,逐项累加 roiNums 并与 ROI 数组长度比较,任一时刻超出剩余长度或最终总和不等时通过 PyErr_SetString 设置 ValueError 并返回 false。
  • 批量 crop 与 crop-and-paste 接入校验: 在 WrapAclDvppVpcBatchCropAsync 和 WrapAclDvppVpcBatchCropAndPasteAsync 中,于 ProcessArray 之后、转换 cropAreas 之前调用 CheckBatchRoiArrayLength 校验 ROI 数量总和与 cropSize。
  • crop-resize 系列接入校验: 在 WrapAclDvppVpcBatchCropResizeAsync、WrapAclDvppVpcBatchCropResizePasteAsync 和 WrapAclDvppVpcBatchCropResizeMakeBorderAsync 中,调用 CheckBatchRoiArrayLength 校验 roiNums 与 cropAreasSize。
  • paste/border 配对数组长度校验: 在 WrapAclDvppVpcBatchCropResizePasteAsync 中新增 pasteAreasSize == cropAreasSize 检查;在 WrapAclDvppVpcBatchCropResizeMakeBorderAsync 中新增 borderCfgsSize == cropAreasSize 检查,不匹配时以 PyExc_ValueError 报错。

🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
atomgit-bot
atomgit-bot
Oct 20 Comments:

代码审查

✅ 未发现问题


🧩 本次 Review 已使用自定义 Skill:

likedislike
Incorrect?
CANN-robotCANN-robotCollaborators
Oct 20 Added label: cann-cla/yes
CANN-robot
CANN-robotCollaborators
Oct 20 Comments:

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 ✅ 卢煜坤, zhangpengpeng8 (2/2) ✅ 卢煜坤 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies 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. 👍

likedislike
CANN-robotCANN-robotCollaborators
Oct 20 Set wangtao43,zhangpengpeng8,yanmingxiang,Reyn52166,ykl999,houyanbao,tingwood as approver
CANN-robotCANN-robotCollaborators
Oct 20 Set wangtao43,zhangpengpeng8,yanmingxiang,Reyn52166,ykl999,houyanbao,tingwood as approver
KaranocaVe
KaranocaVe
Oct 20 Comments:

/compile

likedislike
KaranocaVeKaranocaVe
Oct 20 Pre merge succeeded (commit_id: ccdb8026c55d25315863ab48540d82c15fe260ef)
CANN-robot
CANN-robotCollaborators
Oct 20 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Oct 20 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 20 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 20 Added label: ci-pipeline-passed
KaranocaVe
KaranocaVe
Oct 21 Comments:

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

likedislike
KaranocaVe
KaranocaVe
Oct 21 Comments:

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

likedislike
KaranocaVe
KaranocaVe
Oct 23 Comments:

/compile

likedislike
KaranocaVeKaranocaVe
Oct 23 Pre merge succeeded (commit_id: 8e8cd8e530fa13cb1176e48a19a78a8ba20d1b8f)
CANN-robot
CANN-robotCollaborators
Oct 23 Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
Oct 23 Removed label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
Oct 23 Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 23 Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
Oct 23 Added label: ci-pipeline-passed
KaranocaVe
KaranocaVe
28 days ago Comments:

再次提醒:根据 CANN-robot 当前审批进度,该 PR 仍缺少必要的代码检视或合入审批。麻烦 yanmingxiang Reyn52166 wangtao43 tingwood zhangpengpeng8 ykl999 houyanbao 抽空协助审核;确认无误后请按仓库规则执行 /lgtm 和 /approve,谢谢!

likedislike
KaranocaVe
KaranocaVe
28 days ago Comments:

再次提醒:根据 CANN-robot 当前审批进度,该 PR 仍缺少必要的代码检视或合入审批。麻烦 @yanmingxiang @Reyn52166 @wangtao43 @tingwood @zhangpengpeng8 @ykl999 @houyanbao 抽空协助审核;确认无误后请按仓库规则执行 /lgtm 和 /approve,谢谢!

likedislike
KaranocaVe
KaranocaVe
25 days ago Comments:

当前 PR 状态已满足 CI、CLA、冲突和审批门槛;我尝试直接合入时 GitCode 返回 HTTP 405:You do not have permissions to push into target branch。请具备 runtime/master 写权限的维护者执行合入。

likedislike
ykl999
ykl999Collaborators
23 days ago Comments:

/compile

likedislike
KaranocaVeKaranocaVe
23 days ago Pre merge succeeded (commit_id: 6faa395a8c3fe7e93fd44779475f75011b0b2075)
ykl999
ykl999Collaborators
23 days ago Comments:

/approve
/lgtm

likedislike
CANN-robotCANN-robotCollaborators
23 days ago Added label: approved
CANN-robot
CANN-robotCollaborators
23 days ago Comments:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robotCollaborators
23 days ago Removed label: ci-pipeline-passed
CANN-robotCANN-robotCollaborators
23 days ago Added label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
23 days ago Removed label: ci-pipeline-running
CANN-robotCANN-robotCollaborators
23 days ago Added label: ci-pipeline-passed
zhangpengpeng8
zhangpengpeng8Collaborators
23 days ago Comments:

/lgtm

likedislike
CANN-robotCANN-robotCollaborators
23 days ago Added label: lgtm
CANN-robotCANN-robotCollaborators
23 days ago Merged pull request