From b6447542269e5c7788f372affc68a594b7863f6b Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Mon, 6 Oct 2025 15:29:44 +0300 Subject: [PATCH] Merge pull request #27865 from MaximSmolskiy:fix_invalid_memory_access_in_usac Fix invalid memory access in USAC #27865 ### Pull Request Readiness Checklist Fix #27863 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 - [ ] 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/usac/fundamental_solver.cpp | 4 ++-- modules/calib3d/src/usac/homography_solver.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/calib3d/src/usac/fundamental_solver.cpp b/modules/calib3d/src/usac/fundamental_solver.cpp index d2fb6d3d10..b3ef5b0fc0 100644 --- a/modules/calib3d/src/usac/fundamental_solver.cpp +++ b/modules/calib3d/src/usac/fundamental_solver.cpp @@ -385,7 +385,7 @@ public: Matx AtA_(AtA), U, Vt; Vec W; SVD::compute(AtA_, W, U, Vt, SVD::FULL_UV + SVD::MODIFY_A); - models = std::vector { Mat_(3, 3, Vt.val + 72 /*=8*9*/) }; + models = std::vector { Mat_(3, 3, Vt.val + 72 /*=8*9*/).clone() }; #endif } @@ -503,7 +503,7 @@ public: Matx AtA_(covariance), U, Vt; Vec W; SVD::compute(AtA_, W, U, Vt, SVD::FULL_UV + SVD::MODIFY_A); - models = std::vector { Mat_(3, 3, Vt.val + 72 /*=8*9*/) }; + models = std::vector { Mat_(3, 3, Vt.val + 72 /*=8*9*/).clone() }; #endif if (enforce_rank) FundamentalDegeneracy::recoverRank(models[0], is_fundamental); diff --git a/modules/calib3d/src/usac/homography_solver.cpp b/modules/calib3d/src/usac/homography_solver.cpp index 3be5f2dc20..fe528f59a6 100644 --- a/modules/calib3d/src/usac/homography_solver.cpp +++ b/modules/calib3d/src/usac/homography_solver.cpp @@ -253,7 +253,7 @@ public: Matx Vt; Vec D; if (! eigen(Matx(AtA), D, Vt)) return 0; - H = Mat_(3, 3, Vt.val + 72/*=8*9*/); + H = Mat_(3, 3, Vt.val + 72/*=8*9*/).clone(); #endif } const auto * const h = (double *) H.data;