From 2083fdc9c0476389fcefa71fe245423cfe480f5f Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Sat, 20 May 2023 14:39:06 -0400 Subject: [PATCH] Fixed UBSan warning about undefined pointer arithmetic overflow Pointer arithmetic overflow is always undefined, whether signed or unsigned. It warned here: `Addition of unsigned offset to 0x00017fd31b97 overflowed to 0x00017fd30c97` Convert the offset to a signed number, so that we can offset either forward or backwards. In my own use of OpenCV at least, this is the only case of pointer arithmetic overflow. --- modules/imgproc/src/filter.simd.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/filter.simd.hpp b/modules/imgproc/src/filter.simd.hpp index 966de94c0b..8dcf5235af 100644 --- a/modules/imgproc/src/filter.simd.hpp +++ b/modules/imgproc/src/filter.simd.hpp @@ -44,6 +44,8 @@ #include "opencv2/core/hal/intrin.hpp" #include "filter.hpp" +#include + #if defined(CV_CPU_BASELINE_MODE) #if IPP_VERSION_X100 >= 710 #define USE_IPP_SEP_FILTERS 1 @@ -304,7 +306,7 @@ void FilterEngine__apply(FilterEngine& this_, const Mat& src, Mat& dst, const Si FilterEngine__start(this_, wsz, src.size(), ofs); int y = this_.startY - ofs.y; FilterEngine__proceed(this_, - src.ptr() + y*src.step, + src.ptr() + y * (ptrdiff_t)src.step, (int)src.step, this_.endY - this_.startY, dst.ptr(),