已关闭
【缺陷报告】数据类型截断 - 文件cast.h - 函数CastExtendWithMaskMode - 行号134 #259
zhangjunkai9创建于 27 天前关闭于 12 天前
27 天前 将 gcw_V3YyYBt1 设为负责人
wangmingming
27 天前 评论:
27 天前 评论:
你好,感谢建议, 后续分析处理


19 天前 关联了pull request:fix: 修复 Gather 回绕及 BrcInline/Cast/Concat 截断(#256 #258 #259 #260)
12 天前 issue状态由 进行中 改变为 已完成
12 天前 关闭了 issue
缺陷信息
缺陷描述
函数 CastExtendWithMaskMode 的入参 output_last_dim_stride(uint32_t)在第134行经 output_last_dim_stride * sizeof(OutT) / ONE_BLK_SIZE 计算后,结果直接赋值给 uint8_t dst_repeat_stride(8位硬件指令参数)。当 stride 超过 255 blocks(如 float 输出时 stride > 255*8=2040 元素)时高位截断,导致 Cast 指令使用错误的 repeat stride。该函数被 CastExtend(cast.h:273)调用,CastExtend 被 codegen/cast_api_call.cpp 调用,output_last_dim_stride 来自 tiling 的 output_second_to_last_stride。无范围检查。
事实核查
数据流证据
传播路径:
修复建议
uint32_t dst_rpt_stride = output_last_dim_stride * sizeof(OutT) / ONE_BLK_SIZE; ASCENDC_ASSERT(dst_rpt_stride <= UINT8_MAX, { KERNEL_LOG(KERNEL_ERROR, "dst_repeat_stride exceeds 255: %u", dst_rpt_stride); }); uint8_t dst_repeat_stride = static_cast<uint8_t>(dst_rpt_stride);