From e665be1d70931a0117593bc48ad5fe13fa0f5de9 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Fri, 9 Jun 2017 00:16:58 +0000 Subject: [PATCH] photo: fix integer overflow There is no cast to wide integer type: std::numeric_limits::max() * std::numeric_limits::max() --- modules/photo/src/fast_nlmeans_denoising_opencl.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/photo/src/fast_nlmeans_denoising_opencl.hpp b/modules/photo/src/fast_nlmeans_denoising_opencl.hpp index f012de507d..216ba6dd62 100644 --- a/modules/photo/src/fast_nlmeans_denoising_opencl.hpp +++ b/modules/photo/src/fast_nlmeans_denoising_opencl.hpp @@ -52,8 +52,8 @@ static bool ocl_calcAlmostDist2Weight(UMat & almostDist2Weight, FT almostDist2ActualDistMultiplier = (FT)(1 << almostTemplateWindowSizeSqBinShift) / templateWindowSizeSq; const FT WEIGHT_THRESHOLD = 1e-3f; - int maxDist = normType == NORM_L1 ? std::numeric_limits::max() * cn : - std::numeric_limits::max() * std::numeric_limits::max() * cn; + WT maxDist = normType == NORM_L1 ? (WT)std::numeric_limits::max() * cn : + (WT)std::numeric_limits::max() * (WT)std::numeric_limits::max() * cn; int almostMaxDist = (int)(maxDist / almostDist2ActualDistMultiplier + 1); FT den[4]; CV_Assert(hn > 0 && hn <= 4);