Files
opencv-MIRROR/modules/calib3d/test
Hardik K 06dbed2175 calib3d: fix USAC getLambda out-of-bounds on single support vectors (#31058)
* 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.
2026-11-25 16:52:45 +05:30
..
2018-02-03 19:39:47 +00:00
2019-01-14 22:21:21 +03:00
2018-02-03 19:39:47 +00:00
2018-02-03 19:39:47 +00:00