CV_Assert that function exists in arithm_op#24623
CV_Assert that function exists in arithm_op#24623tozanski wants to merge 1 commit intoopencv:4.xfrom
Conversation
8186816 to
ebdf7c9
Compare
ebdf7c9 to
1136d8d
Compare
| Mat src1 = psrc1->getMat(), src2 = psrc2->getMat(), dst = _dst.getMat(); | ||
| Size sz = getContinuousSize2D(src1, src2, dst, src1.channels()); | ||
| tab[depth1](src1.ptr(), src1.step, src2.ptr(), src2.step, dst.ptr(), dst.step, sz.width, sz.height, usrdata); | ||
| BinaryFuncC func = tab[depth1]; |
There was a problem hiding this comment.
if depth1 is not supported, tab[depth1] leads to out-of-bound access and UB in C++. The tab size should be checked before the tab access.
There was a problem hiding this comment.
In OpenCV5, the length of function table array is fixed as CV_DEPTH_MAX. I think this idea is good.
opencv/modules/core/src/arithm.cpp
Lines 872 to 875 in bae435a
depth1 is calculated with CV_MAT_DEPTH(), so it is smaller than CV_DEPTH_MAX.
However in OpenCV4, this array length is shorten than CV_DEPTH_MAX. I believe it may be fixed.
opencv/modules/core/src/arithm.cpp
Lines 869 to 872 in 408730b
This is only idea, but instead of checking depth1 value, how about to define this array length ?
|
Filed #24703. The PR is closed. |
Arithmetic like addition and subtraction on CV_16F matrices lead to SEGFAULT due to a call of NULL function, added CV_Assert to change it into an exception
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.