fix data overflow problem in GaussianBlur
authorXinguang Bian <mightbxg@hotmail.com>
Fri, 21 May 2021 07:17:20 +0000 (15:17 +0800)
committerXinguang Bian <mightbxg@hotmail.com>
Fri, 21 May 2021 07:17:20 +0000 (15:17 +0800)
modules/imgproc/src/smooth.simd.hpp
modules/imgproc/test/test_smooth_bitexact.cpp

index 6c41b45e9ffc64ddeba2f3c80878da546c8f22ad..3a39765c71f2f9b7e5e2359474dc46cd563504b4 100644 (file)
@@ -1236,8 +1236,12 @@ void hlineSmoothONa_yzy_a<uint16_t, ufixedpoint32>(const uint16_t* src, int cn,
         v_mul_expand(vx_load(src + pre_shift * cn), vx_setall_u16((uint16_t) *((uint32_t*)(m + pre_shift))), v_res0, v_res1);
         for (int j = 0; j < pre_shift; j ++)
         {
+            v_uint16 v_weight = vx_setall_u16((uint16_t) *((uint32_t*)(m + j)));
             v_uint32 v_add0, v_add1;
-            v_mul_expand(vx_load(src + j * cn) + vx_load(src + (n - 1 - j)*cn), vx_setall_u16((uint16_t) *((uint32_t*)(m + j))), v_add0, v_add1);
+            v_mul_expand(vx_load(src + j * cn), v_weight, v_add0, v_add1);
+            v_res0 += v_add0;
+            v_res1 += v_add1;
+            v_mul_expand(vx_load(src + (n - 1 - j)*cn), v_weight, v_add0, v_add1);
             v_res0 += v_add0;
             v_res1 += v_add1;
         }
index f446deb8d8636b74d74c710b6f1497f2c0456865..246f1df7980b06fe3d26a36b5efdb764f7638935 100644 (file)
@@ -220,6 +220,15 @@ TEST(GaussianBlur_Bitexact, regression_15015)
     ASSERT_EQ(0.0, cvtest::norm(dst, src, NORM_INF));
 }
 
+TEST(GaussianBlur_Bitexact, overflow_20121)
+{
+    Mat src(100, 100, CV_16UC1, Scalar(65535));
+    Mat dst;
+    GaussianBlur(src, dst, cv::Size(9, 9), 0.0);
+    double min_val;
+    minMaxLoc(dst, &min_val);
+    ASSERT_EQ(cvRound(min_val), 65535);
+}
 
 static void checkGaussianBlur_8Uvs32F(const Mat& src8u, const Mat& src32f, int N, double sigma)
 {