已关闭
【缺陷报告】空指针解引用 - 文件histogram_v2_op_tiling.cpp - 函数HistogramV2Tiling::Init - 行号159 #2772
zhangjunkai9创建于  20 天前关闭于  17 天前
zhangjunkai9
20 天前 创建

缺陷信息

缺陷类型nullptrDeref (空指针解引用)
函数HistogramV2Tiling::Init
文件math/histogram_v2/op_host/histogram_v2_op_tiling.cpp
行号159
置信度90%

缺陷描述

tilingContext->GetInputShape(0) 返回值未做空指针校验即在第159行被解引用调用 GetStorageShape()。同模块 histogram_v2_simt_tiling.cpp:115 对 GetInputShape 返回值使用了 OP_CHECK_NULL_WITH_CONTEXT 检查,证明该 API 可能返回 nullptr;histogram_v2_base_tiling.cpp:31-34 也对 GetCompileInfo 返回值做了空指针校验。若 GetInputShape(0) 返回 nullptr,第159行 ->GetStorageShape() 将导致空指针解引用崩溃

事实核查

经复核源代码确认,第159行 tilingContext->GetInputShape(0)->GetStorageShape() 对 GetInputShape(0) 返回值直接解引用,未做任何空指针校验。

同模块 histogram_v2_simt_tiling.cpp:114-115 对 GetInputShape 返回值使用了 OP_CHECK_NULL_WITH_CONTEXT 检查,histogram_v2_base_tiling.cpp:31-34 对 GetCompileInfo 返回值也做了空指针校验,证明该代码库中 GetInputShape API 确实可能返回 nullptr 且项目惯例是需要校验的。

该函数通过 HistogramV2MembaseTiling::DoOpTiling(第268行)调用,DoOpTiling 是框架注册的 tiling 回调(第288行 REGISTER_OPS_TILING_TEMPLATE),由框架在算子编译时调用,调用链可达。

缺陷真实存在。

数据流证据

Source(问题源头)

math/histogram_v2/op_host/histogram_v2_op_tiling.cpp:42 行 gert::TilingContext* tilingContext 作为成员变量存储(来自构造函数参数,由框架传入)

Sink(问题爆发点)

math/histogram_v2/op_host/histogram_v2_op_tiling.cpp:159 行 tilingContext->GetInputShape(0)->GetStorageShape() 对 GetInputShape(0) 返回值直接解引用(空指针解引用 sink)

传播路径:

# 文件 行号 说明
1 math/histogram_v2/op_host/histogram_v2_op_tiling.cpp 42 tilingContext 由构造函数参数赋值给成员变量
2 math/histogram_v2/op_host/histogram_v2_op_tiling.cpp 159 tilingContext->GetInputShape(0) 返回值未经空指针校验直接调用 ->GetStorageShape() 解引用(sink)

修复建议

auto inputShape = tilingContext->GetInputShape(0);
OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputShape);
auto selfShape = inputShape->GetStorageShape();
likedislike
陈思
陈思成员
20 天前 评论:

分析结论

已核对当前 masterHistogramV2 tiling 直接解引用 GetInputShape(0) 的返回值,局部没有判空,属于防御性检查遗漏。

该输入在算子定义中为必需输入,正常框架调用应保证 shape 存在;现有材料尚未证明合法调用可产生空 shape。因此更准确的影响是异常或单测构造不完整上下文时可能崩溃。

建议获取 shape 后立即判空并返回失败,补充缺失必需输入 shape 的异常测试。后续由责任人安排修复和验证。

likedislike
Nice tryNice try成员
19 天前 将 Nice_try 设为负责人
Nice tryNice try成员
18 天前 关联了pull request:fix nullptrDef of histogram_v2 and add ut test
CANN-robotCANN-robot成员
17 天前 关闭了 issue
CANN-robotCANN-robot成员
17 天前 添加了label:resolved