mirror of
https://github.com/opencv/opencv.git
synced 2026-12-02 12:12:06 -06:00
* calib3d: fix USAC getLambda out-of-bounds on single support vectors Fixes #27487 In usac::getLambda(), the median calculation had an inverted odd/even parity check and accessed supports[size/2 + 1] when size % 2 was non-zero. When evaluating a single model (supports.size() == 1), supports[1] was accessed out of bounds, which triggered a debug assertion (vector subscript out of range) in debug builds and caused undefined reads in release builds. This patch: - Inlines getLambda in usac.hpp without CV_EXPORTS to avoid altering the 4.x shared library ABI. - Corrects the median calculation to use supports[size/2] for odd sizes and (supports[size/2 - 1] + supports[size/2]) * 0.5 for even sizes. - Guards empty support vectors and clamps denominators to avoid divisions by zero. * calib3d: add deterministic test coverage for getLambda Add direct regression tests in test_usac.cpp: - Empty support vector returns 1.0 and sets min_non_random_inliers to 1. - Single-element vector (supports.size() == 1) validates fix against out-of-bounds read and crash. - Even-sized vector (supports.size() == 4) validates two-middle-element median. - Odd-sized vector (supports.size() == 3) validates middle-element median. - Validates denominator handling and min_non_random_inliers when is_independent is true.