Merge pull request #27321 from vrabaud:norm

Make sure to not access outside normDiffTabMake sure to not access outside normDiffTab #27321 

If the norm is outside the array (e.g. Hamming), memory is read outside of the array, which does not matter because the invalid pointer is not used oustide of the function (e.g. the Hamming path is taken) but it triggers the sanitizer.

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Vincent Rabaud 2025-05-17 08:59:08 +02:00 committed by GitHub
parent f3cffcd85d
commit 9201ca1af1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 2 additions and 1 deletions

View File

@ -571,7 +571,7 @@ double norm( InputArray _src1, InputArray _src2, int normType, InputArray _mask
((normType == NORM_HAMMING || normType == NORM_HAMMING2) && src1.type() == CV_8U) );
NormDiffFunc func = getNormDiffFunc(normType >> 1, depth == CV_16F ? CV_32F : depth);
CV_Assert( func != 0 );
CV_Assert( (normType >> 1) >= 3 || func != 0 );
if( src1.isContinuous() && src2.isContinuous() && mask.empty() )
{

View File

@ -1350,6 +1350,7 @@ NormDiffFunc getNormDiffFunc(int normType, int depth)
(NormDiffFunc)normDiffL2_64f, 0
}
};
if (normType >= 3 || normType < 0) return nullptr;
return normDiffTab[normType][depth];
}