Fix potential NaN in cv::norm.#20263
Conversation
|
I can add the following test to core/tests/test_arithm.cpp but it does not fail on the 3.X branch, only on the 4.x branch: |
|
Yes, please add this test. |
cb95a0f to
36f94d6
Compare
|
I added a test: it fails on 3.x and 4.x as the norm is a NaN. |
There can be an int overflow. cv::norm( InputArray _src, int normType, InputArray _mask ) is fine, not cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _mask ).
alalek
left a comment
There was a problem hiding this comment.
Thank you for the fix and test!
Reproduced on both 3.4/master branches.
| const int intSumBlockSize = (normType == NORM_L1 && depth <= CV_8S ? (1 << 23) : (1 << 15))/cn; | ||
| const int blockSize = std::min(total, intSumBlockSize); | ||
| int isum = 0; |
There was a problem hiding this comment.
(1 << 15)
Parent of the mentioned commit contains the similar code.
The change which introduces regression is:
-unsigned isum = 0;
+int isum = 0int type is used here to follow the parameter type of used processing functions (see NormDiffFunc)
The proposed change is correct (also fixes 3.4.9 on test with kSize = 200).
Regression is introduced here by adding of block processing: https://github.com/opencv/opencv/blame/ab0f0f26a1d82e71d756a8b08f061a69214a0f10/modules/core/src/stat.cpp#L1214
There can be an int overflow.
cv::norm( InputArray _src, int normType, InputArray _mask ) is fine,
not cv::norm( InputArray _src1, InputArray _src2, int normType, InputArray _mask ).
The fix and bug were both introduced in 34530da
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request