Open
【缺陷报告】整数溢出(含上溢出/下溢出) - 文件kernel_operator_vec_reduce_impl.h - 函数isMasked - 行号1365 #1861
zhangjunkai9Add on 27 days ago
27 days ago Associated pull request
27 days ago Associated pull request
li_fangyuan
25 days ago Comments:
25 days ago Comments:
您好,相关问题已修复,已修改bit_to_check的声明类型和位操作逻辑


li_fangyuan
25 days ago Comments:
25 days ago Comments:
/close


CANN-robot
25 days ago Comments:
25 days ago Comments:
Notice
@li_fangyuan , you can't close an issue unless you are the author of it or a collaborator.


li_fangyuan
25 days ago Comments:
25 days ago Comments:
/assign


25 days ago Assign li_fangyuan as responsible person
li_fangyuan
25 days ago Comments:
25 days ago Comments:
/close


CANN-robot
25 days ago Comments:
25 days ago Comments:
Notice
@li_fangyuan , you can't close an issue unless you are the author of it or a collaborator.


20 days ago changed custom category from 任务 to 缺陷
缺陷信息
缺陷描述
在 isMasked 函数第 1365 行,表达式
uint32_t bit_to_check = (1 << (inRepeatIndex % 64))存在有符号整数移位溢出(未定义行为)缺陷。字面量1的类型为int(32 位有符号),当inRepeatIndex % 64的结果 >= 32 时,1 << 32或更大的移位量会导致有符号整数溢出,属于 C/C++ 标准中的未定义行为(UB)。调用方 IterateSrc(第 1388 行)计算inRepeatIndex = j * blockLen + k,其中 blockCount=8,blockLen = 32/sizeof(T)。对于 half 类型(sizeof=2),blockLen=16,最大 inRepeatIndex = 7*16 + 15 = 127,127 % 64 = 63 >= 32,触发 UB。对于 float 类型(sizeof=4),blockLen=8,最大 inRepeatIndex = 7*8 + 7 = 63,63 % 64 = 63 >= 32,同样触发 UB。该函数通过 GetReduceMaxMinCountImpl → IterateSrc 调用链可达,且 bitwiseMask 为 true 时执行此路径。事实核查
数据流证据
传播路径:
修复建议
将字面量 1 改为无符号类型以避免有符号移位溢出: uint32_t bit_to_check = (1u << (inRepeatIndex % 64));