已关闭
【缺陷报告】空指针解引用 - 文件histogram_v2_infershape.cpp - 函数HistogramV2InferShapeFunc - 行号29 #2771
zhangjunkai9创建于  20 天前关闭于  16 天前
zhangjunkai9
20 天前 创建

缺陷信息

缺陷类型nullptrDeref (空指针解引用)
函数HistogramV2InferShapeFunc
文件math/histogram_v2/op_host/histogram_v2_infershape.cpp
行号29
置信度90%

缺陷描述

attr->GetAttrPointer<int64_t>(BINS_IDX)返回值未做空指针校验即通过*运算符解引用。同模块histogram_fixed_width_infershape.cpp:47-48对GetAttrPointer返回值使用OP_CHECK_NULL_WITH_CONTEXT检查,本文件虽检查了attr非空但未检查GetAttrPointer返回值,若属性缺失则解引用崩溃

事实核查

经复核源代码确认,第29行 *(attr->GetAttrPointer<int64_t>(BINS_IDX)) 直接解引用GetAttrPointer返回值,未做nullptr检查。

同模块代码对比:histogram_fixed_width_infershape.cpp:47-48对GetAttrPointer返回值使用OP_CHECK_NULL_WITH_CONTEXT检查;

histogram_v2_simt_tiling.cpp:126-127先赋值给binsPtr再判空后解引用;

histogram_v2_graph_infer.cpp:31-33也检查了yDtypePtr != nullptr。

本文件虽第28行检查了attr非空,但GetAttrPointer在属性缺失时仍可返回nullptr,且同模块已有成熟防护模式,本处缺失防护是真实缺陷。

调用链经IMPL_OP_INFERSHAPE注册可达。

数据流证据

Source(问题源头)

math/histogram_v2/op_host/histogram_v2_infershape.cpp:27 行 auto attr = context->GetAttrs() 获取attrs对象

Sink(问题爆发点)

math/histogram_v2/op_host/histogram_v2_infershape.cpp:29 行 *(attr->GetAttrPointer<int64_t>(BINS_IDX)) 解引用GetAttrPointer返回值(空指针解引用sink)

传播路径:

# 文件 行号 说明
1 math/histogram_v2/op_host/histogram_v2_infershape.cpp 27 auto attr = context->GetAttrs() 获取attrs对象
2 math/histogram_v2/op_host/histogram_v2_infershape.cpp 28 OP_CHECK_NULL_WITH_CONTEXT(context, attr) 检查attr非空(有效保护)
3 math/histogram_v2/op_host/histogram_v2_infershape.cpp 29 *(attr->GetAttrPointer<int64_t>(BINS_IDX)) 直接解引用GetAttrPointer返回值,未做nullptr检查(缺失保护)

调用链

可达调用链1 起点:(entry functions) → 终点:ops::HistogramV2InferShapeFunc 深度:0

# 文件 函数 函数起始行 调用点行
1 math/histogram_v2/op_host/histogram_v2_infershape.cpp:ops: HistogramV2InferShapeFunc 23

修复建议

auto binsPtr = attr->GetAttrPointer<int64_t>(BINS_IDX);
OP_CHECK_NULL_WITH_CONTEXT(context, binsPtr);
int64_t bins = *binsPtr;
likedislike
陈思
陈思成员
19 天前 评论:

分析结论

已核对当前 masterHistogramV2 tiling 中通过 GetAttrPointer<int64_t> 取得 bins 后直接解引用,局部代码确实没有判空。

bins 在算子定义中是带默认值 100 的可选属性,正常框架路径应提供有效值;现有材料未证明合法调用可得到空指针。因此当前确认的是异常/构造不完整上下文下的防御性缺口,不足以认定正常路径可达崩溃。

建议显式判空后失败或回落到定义默认值,并补充缺失属性上下文测试。后续由责任人安排修复和验证。

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