Skip to content

Commit 7e83e39

Browse files
committed
dnn(ocl): fix out of bounds reading in case of filter >= outputs
1 parent b65d7e3 commit 7e83e39

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

modules/dnn/src/opencl/conv_spatial_helper.cl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,7 @@ __kernel void TEMPLATE(copyWeightsSwizzled, Dtype)
8484
int idxOut = FP*(kernel_w*kernel_h*channels*swizzleFactor) + kernel_C*(kernel_w*kernel_h*swizzleFactor) + kernel_Y*(kernel_w*swizzleFactor) + kernel_X*swizzleFactor + F1;
8585
int idxIn = filter*(kernel_w*kernel_h*channels) + kernel_C*(kernel_w*kernel_h) + kernel_Y*kernel_w + kernel_X;
8686

87-
weightOut[idxOut] = weightIn[idxIn];
87+
// idxIn is not valid if (filter >= outputs) - no data for these elements. Output gaps are filled by zeros
88+
Dtype v = (filter < outputs) ? weightIn[idxIn] : (Dtype)0;
89+
weightOut[idxOut] = v;
8890
}

0 commit comments

Comments
 (0)