已关闭
【缺陷报告】空指针解引用 - 文件transpose_quant_batch_mat_mul_infershape.cpp - 函数InferShapeForTransposeQuantBatchMatMul - 行号220 #5017
zhangjunkai9创建于  27 天前关闭于  23 天前
zhangjunkai9
27 天前 创建

缺陷信息

缺陷类型nullptrDeref (空指针解引用)
函数InferShapeForTransposeQuantBatchMatMul
文件matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp
行号220
置信度90%

缺陷描述

在 InferShapeForTransposeQuantBatchMatMul 函数中,batchSplitFactor 在第190行通过 attrs->GetAttrPointer<int32_t>(5) 获取,该方法可能返回 nullptr(同一函数第167-168行对属性0的 GetAttrPointer 返回值做了显式 nullptr 检查,证明 GetAttrPointer 确实可能返回 nullptr)。第216行的 CHECK 宏使用 && 逻辑:batchSplitFactor != nullptr && *batchSplitFactor != VALID_BATCH_SPLIT_FACTOR,当 batchSplitFactor 为 nullptr 时,由于 C++ 短路求值,第一个条件为 false,整个条件为 false,CHECK 宏不触发返回,执行继续到第220行。第220行 SetShapeY 调用中 *batchSplitFactor 直接解引用可能为 nullptr 的指针,导致空指针解引用崩溃。该函数通过 entry_callchain 确认可从程序入口直接到达。

事实核查

核查1成立:第190行batchSplitFactor由GetAttrPointer获取(可能返回nullptr,第167-168行对属性0的显式nullptr检查证明此点),第216行CHECK使用&&短路求值,当batchSplitFactor为nullptr时条件为false不触发返回,第220行*batchSplitFactor直接解引用构成空指针解引用缺陷。

核查2无有效防护:第216行CHECK逻辑恰好遗漏了nullptr情况。

核查3函数可达:entry_callchain显示为入口函数。

核查4触发可满足:GetAttrPointer返回nullptr是合理场景。

数据流证据

Source(问题源头)

matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp:190 行 const auto batchSplitFactor = attrs->GetAttrPointer<int32_t>(5) 从属性指针获取 batchSplitFactor(GetAttrPointer 可能返回 nullptr,同函数第168行对属性0做了显式 nullptr 检查证明此点)

Sink(问题爆发点)

matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp:220 行 SetShapeY(*shapeY, shapeX1Transposed, shapeX2Transposed, *permY, *batchSplitFactor) 直接解引用可能为 nullptr 的 batchSplitFactor(空指针解引用 sink)

传播路径:

# 文件 行号 说明
1 matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp 167 const auto dtype = attrs->GetAttrPointer<int64_t>(0) 同函数内对属性0调用 GetAttrPointer 并做 nullptr 检查,证明 GetAttrPointer 可返回 nullptr
2 matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp 168 CHECK(dtype == nullptr, ..., return ge::GRAPH_FAILED) 对属性0的 nullptr 检查保护就位,但属性5(batchSplitFactor)无此保护
3 matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp 190 const auto batchSplitFactor = attrs->GetAttrPointer<int32_t>(5) 获取属性5指针,无 nullptr 检查(传播节点:形参接收点)
4 matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp 216 CHECK(batchSplitFactor != nullptr && *batchSplitFactor != VALID_BATCH_SPLIT_FACTOR, ..., return ge::GRAPH_FAILED) 逻辑缺陷:当 batchSplitFactor 为 nullptr 时短路求值使条件为 false,CHECK 不触发返回,未保护后续解引用
5 matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp 220 *batchSplitFactor 在 SetShapeY 调用中直接解引用可能为 nullptr 的指针(危险操作点/sink)

调用链

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

# 文件 函数 函数起始行 调用点行
1 matmul/transpose_quant_batch_mat_mul/op_host/transpose_quant_batch_mat_mul_infershape.cpp InferShapeForTransposeQuantBatchMatMul 154

修复建议

CHECK(batchSplitFactor == nullptr,
      CUBE_INNER_ERR_REPORT(nameOp, "batchSplitFactor is null."), return ge::GRAPH_FAILED);
CHECK(*batchSplitFactor != VALID_BATCH_SPLIT_FACTOR,
      CUBE_INNER_ERR_REPORT(nameOp, "batchSplitFactor should be 1 ."), return ge::GRAPH_FAILED);
likedislike
wmg1
wmg1
27 天前 评论:

/assign

likedislike
CANN-robotCANN-robot成员
27 天前 将 wmg1 设为负责人
林泽辉成员
26 天前 评论:

/assign

likedislike
CANN-robotCANN-robot成员
26 天前 将 linzehui2058 设为负责人,移除负责人 wmg1
jgx
jgx成员
26 天前 评论:

/assign

likedislike
CANN-robotCANN-robot成员
26 天前 将 jgx12 设为负责人,移除负责人 linzehui2058
CANN-robotCANN-robot成员
23 天前 关闭了 issue
CANN-robotCANN-robot成员
23 天前 添加了label:resolved