Pull Request已成功合入, 合并人@CANN-robot
(感谢 zhangyiyi 的贡献)变更摘要
本 PR 针对 bounding_box_encode 算子的 geir(图模式)通路补齐了缺失的参数校验逻辑。原先 InferShape 和 InferDataType 为空壳透传实现,README 声明的 8 条输入约束中仅 2 条能被拦截。此次修复在 tiling 层和 InferShape 层分别补全了 dtype 一致性、rank==2、shape[1]==4、shape 完全一致、means/stds 长度==4 等校验,并通过 NPU 负向测试矩阵验证了拦截有效性。
主要改动
-
新增
InferDataType4BoundingBoxEncode:在bounding_box_encode_graph_infer.cpp中实现了图模式的 InferDataType 逻辑,将输出 dtype 设置为与anchor_box输入一致,填补了原先空壳透传的缺失。 -
ParseMeansStds增加长度校验:在bounding_box_encode_tiling_arch35.cpp中,读取means[0..3]和stds[0..3]之前新增GetSize() != 4的检查,消除越界读取风险。 -
新增
CheckInputsConsistency函数:在 tiling 入口处统一校验 anchor 与 groundtruth 的 dtype 一致性、rank==2、最后一维==4、以及 shape 完全相等,并在BoundingBoxEncodeTilingFunc中调用,确保非法输入在 tiling 阶段被拦截。 -
重写
InferShape4BoundingBoxEncode:将原先简单拷贝输入 shape 的空壳实现替换为完整的校验逻辑,包含 dtype 一致性检查、CheckBoxShape辅助函数(支持动态 shape 的 rank 和最后一维校验)、两输入 shape 逐维对比(兼容UNKNOWN_DIM),最终将输出 shape 设为anchorShape。


代码审查
我已经完整审查了全部 3 个文件的变更。让我逐一分析每个文件。
文件 1: bounding_box_encode_graph_infer.cpp(新增文件)
这是一个自动生成的新文件,注册了 InferDataType 回调。逻辑很简单:获取输入 0 的 dtype,设置到输出 0。代码简洁正确,无问题。
文件 2: bounding_box_encode_tiling_arch35.cpp
变更包括:
- 添加
MEANS_STDS_LEN = 4常量 - 在
ParseMeansStds中增加 means/stds 长度校验(防止越界读) - 新增
CheckInputsConsistency函数(校验 dtype 一致性、rank==2、last dim==4、shape 完全相等) - 在
BoundingBoxEncodeTilingFunc入口调用CheckInputsConsistency
文件 3: bounding_box_encode_infershape.cpp
变更包括:
- 添加常量和
CheckBoxShape辅助函数(支持动态 shape) - 重写
InferShape4BoundingBoxEncode,补齐 dtype 一致性、rank、last dim、shape 一致性的校验
我进行了深入的审查,包括边界值分析、空指针路径追踪、类型转换安全性、宏展开兼容性、以及跨文件契约一致性检查。审查结论:此 diff 无实质性缺陷。
各项校验逻辑完整且正确:
- 空指针检查在执行解引用之前完成
- 长度校验在数组访问
[0..3]之前完成 CheckInputsConsistency中的 rank 检查在对GetDim(1)的调用之前完成- 动态 shape 的
UNKNOWN_RANK/UNKNOWN_DIM在CheckBoxShape和形状比较中均被正确处理 - 格式说明符与参数类型匹配(
%zu对应size_t,%ld对应int64_t) - 所有 8 条 README 约束均已覆盖
审查总结
| 文件 | 审查结果 |
|---|---|
objdetect/bounding_box_encode/op_graph/bounding_box_encode_graph_infer.cpp |
无问题 |
objdetect/bounding_box_encode/op_host/arch35/bounding_box_encode_tiling_arch35.cpp |
无问题 |
objdetect/bounding_box_encode/op_host/bounding_box_encode_infershape.cpp |
无问题 |
发现数量:P0: 0, P1: 0, P2: 0, P3: 0
整体风险评估:此变更为低风险。新增的校验逻辑覆盖了原先缺失的 5 条参数约束,代码结构清晰,空指针/越界保护路径完整,动态 shape 场景也做了恰当的兼容处理。未发现正确性、安全性或可靠性问题。
⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。


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
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/ops-cv | ✅ zhangzijie, 周奇龙 (2/2) | ✅ zhangzijie, 周奇龙 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
ugzhangyiyi, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/compile


流水线任务触发成功
任务链接 [f5b4a2332b3f4485accad7d6778afc05][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-cv | ✅ SUCCESS | ||
| UT_Test_report_lcov | ✅ SUCCESS |
[2026-07-27 23:29:10] CI执行结束


流水线任务触发成功
任务链接 [cb8b8d01cacb4e6784e7f54f1a066f2e][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ❌ FAILED | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> |


/compile


流水线任务触发成功
任务链接 [9a5a1615b6264ac28afb2bfca081b7bf][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Pre | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_mobile_station_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_experimental_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910b | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_910c | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_X86_monitor_950 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_classify | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_mobile_station_9030_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| UT_Test | ✅ SUCCESS | ||
| PreSmoke_A900 | ✅ SUCCESS | >>>>> | |
| API_Check | ✅ SUCCESS | >>>>> | |
| PreSmoke_ATK_Test_A2 | ✅ SUCCESS | >>>>> | |
| UT_Test_harmony-infer-chs-cv | ✅ SUCCESS | ||
| UT_Test_report_lcov | ✅ SUCCESS |
[2026-07-28 10:29:56] CI执行结束


流水线任务触发成功
任务链接 [aa79a7c19eb6478996ba1874fdbcae44][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| codecheck_checkpr | ✅ SUCCESS | ||
| StaticCheck_codespell | ✅ SUCCESS | ||
| StaticCheck_link_validity | ✅ SUCCESS | ||
| StaticCheck_resource_existence | ✅ SUCCESS | ||
| StaticCheck_tag_closed | ✅ SUCCESS | ||
| StaticCheck_markdownlint | ✅ SUCCESS | ||
| codecheck_precommit | ✅ SUCCESS | >>>>> |
[2026-07-28 10:20:33] CI执行结束


/lgtm
/approve


本 PR 针对
bounding_box_encode算子的 geir(图模式)通路补齐了 5 条缺失的参数校验代码,并通过真实 NPU负向测试矩阵验证了拦截有效性。
问题背景
经静态分析和 NPU 实测发现,geir 通路的 InferShape/InferDataType 为空壳透传实现,README 中声明的 8 条约束仅有 2 条(dtype
集合、stds≠0)能被拦截,其余 5 条约束(dtype 一致性、shape[1]==4、shape 完全一致、rank==2、means/stds
长度==4)在代码中无任何校验逻辑,导致非法输入静默通过或越界读。
修复方案
在 tiling 层(真实执行路径)补齐全部缺失校验:
means[0..3]和stds[0..3]前先调用GetSize()验证长度为 4,消除越界读风险一致性、rank==2、shape[1]==4、shape 完全相等
生效,但保留以对齐规范)
验证方法
构造 14 例负向/对照测试矩阵(覆盖全部 README 约束 + 边界情况),在真实 NPU 上以完整 AddGraph+RunGraph 流程执行 Before/After
对比:
节点统一类型的结构性限制无法在算子层拦截(已在报告中实证归因)
关联的Issue
https://gitcode.com/cann/ops-cv/issues/650
测试
1. 负向拦截测试(NPU 真机)
tests/geir_intercept/test_geir_intercept.cpp+run_intercept.sh2. 回归测试
3. 环境清理验证
/root/atc_data/kernel_cache/*以避免旧 tiling 行为残留文档更新
tests/geir_intercept/INTERCEPT_REPORT.md(Before/After 对照 + 根因分析 + 修改清单)tests/geir_intercept/test_geir_intercept.cpp(负向测试工程源码)tests/geir_intercept/run_intercept.sh(NPU 编译执行脚本)类型标签