From b7efc11b5167c0210344e3b6d738febf3b2cf12a Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Tue, 6 Jan 2026 09:07:19 +0100 Subject: [PATCH] Merge pull request #28361 from vrabaud:msan Prevent a potential crash in FMEstimatorCallback::runKernel #28361 With solveCubic sometimes failing, n can be -1. ### 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 - [x] There is a reference to the original bug report and related work - [x] 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 --- modules/calib3d/src/fundam.cpp | 2 +- modules/calib3d/test/test_fundam.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/calib3d/src/fundam.cpp b/modules/calib3d/src/fundam.cpp index e107332c95..c6020fcc8f 100644 --- a/modules/calib3d/src/fundam.cpp +++ b/modules/calib3d/src/fundam.cpp @@ -806,7 +806,7 @@ public: Mat F(count == 7 ? 9 : 3, 3, CV_64F, f); int n = count == 7 ? run7Point(m1, m2, F) : run8Point(m1, m2, F); - if( n == 0 ) + if( n <= 0 ) _model.release(); else F.rowRange(0, n*3).copyTo(_model); diff --git a/modules/calib3d/test/test_fundam.cpp b/modules/calib3d/test/test_fundam.cpp index ab987ffcea..58a57dba4a 100644 --- a/modules/calib3d/test/test_fundam.cpp +++ b/modules/calib3d/test/test_fundam.cpp @@ -1673,5 +1673,13 @@ TEST(Calib3d_FindFundamentalMat, correctMatches) cout << np2 << endl; } +TEST(Calib3d_FindFundamentalMat, Crash) +{ + vector m1 = {{245, 128},{284, 226},{140, 60},{133, 127},{71, 218},{152, 138},{181, 106}}; + vector m2 = m1; + vector mask; + findFundamentalMat(m1, m2, mask, FM_LMEDS, 1, 0.99); +} + }} // namespace /* End of file. */