mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 21:22:43 -06:00
geometry: reject negative node indexes in buildMST - #31236 Fixes #31235 ### Problem `buildMST` only rejected node indexes `>= numNodes`, so an edge with a negative `source` or `target` was used to index `parent` (Kruskal) or `adj` (Prim) out of bounds. ### Fix Also reject `u < 0` and `v < 0` in the edge check of both `buildMSTKruskal` and `buildMSTPrim`. ### Tests Added `MSTInvalidInput.negativeNodeIndex`, which checks that both algorithms return `false` for a graph with a negative target and for one with a negative source. It fails without the fix (both return `true`) and passes with it. All 347 tests in `opencv_test_geometry` pass on macOS arm64. ### 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