Skip to content

xfeatures2d: fix matchLOGOS crash with fewer than N neighbors - #4182

Open
JaimeFine wants to merge 1 commit into
opencv:5.xfrom
JaimeFine:fix-4174-5x
Open

xfeatures2d: fix matchLOGOS crash with fewer than N neighbors#4182
JaimeFine wants to merge 1 commit into
opencv:5.xfrom
JaimeFine:fix-4174-5x

Conversation

@JaimeFine

@JaimeFine JaimeFine commented Jul 24, 2026

Copy link
Copy Markdown

Fixes #4174

  • Fix out-of-bounds access in Point::nearestNeighboursNaive() when fewer than N neighbors are available.
  • Resize nnVector to the actual neighbor count to avoid invalid trailing neighbor entries.
  • Add a regression test for the 3-keypoint same-label matchLOGOS reproducer.

Tested:

  • Built opencv_test_xfeatures2d on Windows with OpenCV 5.x + opencv_contrib 5.x
  • Ran LOGOS-related tests with OPENCV_TEST_DATA_PATH set to C:\dev\opencv_extra\testdata

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • 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

NOTE: No new test data or performance test is needed for this bug fix; the regression test uses synthetic keypoints.

@JaimeFine

Copy link
Copy Markdown
Author

The failing GitHub Actions run appears to be unrelated to this patch.

The workflow parser fails before running tests because
.github/workflows/PR-5.x.yaml references a reusable workflow with @geometry_module,
which does not appear to be a valid branch/tag/commit in opencv/ci-gha-workflow?

Local validation for this patch completed successfully.

@JaimeFine

Copy link
Copy Markdown
Author

Hi OpenCV maintainers, gentle follow-up on this small xfeatures2d bug fix.

This PR fixes #4174 by avoiding an out-of-bounds access in matchLOGOS when fewer than N candidate neighbors are available, and adds a synthetic regression test for the small-neighbor case.

I noticed the GitHub Actions workflow did not reach the test stage because of what looks like an unrelated reusable-workflow reference issue. I validated locally on Windows with OpenCV 5.x + opencv_contrib 5.x by building opencv_test_xfeatures2d and running the LOGOS-related tests.

Please let me know if there is anything I should adjust to make the PR easier to review. Also happy to retarget or rebase if 5.x is not the preferred branch for this fix.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant