已关闭
【缺陷报告】空指针解引用 - 文件aclnn_modulate_backward.cpp - 函数CheckMaxDimension - 行号103 #5015
zhangjunkai9创建于 8月24日关闭于 29 天前
zhangqijia1
8月24日 评论:
8月24日 评论:
/assign


8月24日 将 gcw_SUaZx3UQ 设为负责人
8月24日 将 tianqiguang 设为负责人,移除负责人 gcw_SUaZx3UQ
zhangqijia1
8月24日 评论:
8月24日 评论:
/assign


8月24日 将 gcw_SUaZx3UQ 设为负责人,移除负责人 tianqiguang
8月24日 关联了pull request:fix(modulate_grad): 修复 aclnnModulateBackward 中 scale/shift 空指针解引用
29 天前 关闭了 issue
29 天前 添加了label:resolved
缺陷信息
缺陷描述
函数 CheckMaxDimension 的参数 scale 和 shift 为可选参数,可为 nullptr(源码注释 line 151 明确说明 scale和shift参数可以为空)。在第 103 行的 if 条件 (!scale->IsEmpty() || !shift->IsEmpty()) 中,当 grad_output 或 input 为空 tensor 时(IsEmpty() 返回 true),&& 的左操作数为 true,导致右操作数被求值,直接对可能为 nullptr 的 scale/shift 调用 IsEmpty(),触发空指针解引用。同文件的 CheckDtypeValid 和 CheckDimension 函数均使用 CheckNotNullForScaleAndShift 保护 scale/shift 的解引用,唯独此处遗漏。调用路径:aclnnModulateBackwardGetWorkspaceSize(line 164) -> CheckParams(line 175) -> CheckMaxDimension(line 157),entry_callchain 为空但函数在文件内可达。
事实核查
数据流证据
传播路径:
修复建议
static bool CheckMaxDimension(const aclTensor* grad_output, const aclTensor* input, const aclTensor* scale, const aclTensor* shift) { op::Shape gradoutputShape = grad_output->GetViewShape(); size_t gradoutputDimNum = gradoutputShape.GetDimNum(); op::Shape inputShape = input->GetViewShape(); size_t inputDimNum = inputShape.GetDimNum(); if (gradoutputDimNum != MAX_SUPPORT_DIM || inputDimNum != MAX_SUPPORT_DIM) { OP_LOGE(ACLNN_ERR_PARAM_INVALID, "The dimension of self must be 3"); return false; } if ((grad_output->IsEmpty() || input->IsEmpty()) && ((scale != nullptr && !scale->IsEmpty()) || (shift != nullptr && !shift->IsEmpty()))) { OP_LOGE(ACLNN_ERR_PARAM_INVALID, "when grad_output or input is empty, scale and shift must be empty"); return false; } return true; }