Opencv_contrib: GMSMatcher Crashes in debug Mode (vector subscript out of range)

Created on 23 Feb 2020  ·  4Comments  ·  Source: opencv/opencv_contrib

Description:
In '_modules/xfeatures2d/src/gms.cpp_' method GMSMatcher::run crashes in Line 373 in debug mode:

373: if (mCellPairs[mvMatchPairs[i].first] == mvMatchPairs[i].second)
374:                mvbInlierMask[i] = true;

This is because array mCellPairs is indexed with mvMatchPairs[i].first which sometimes has value -1. The Value -1 is written to mCellPairs in method assignMatchPairs line 170:

int lgidx = mvMatchPairs[i].first = getGridIndexLeft(lp, gridType);

were getGridIndexLeft() returns -1 if the feature point coordinates are close to the border. See Line 222:

222:    if (x >= mGridSizeLeft.width || y >= mGridSizeLeft.height)
223:        return -1;

Suggested Fix:

Add additional check for mvMatchPairs[i].first in Line 373:

373: if (mvMatchPairs[i].first>=0 && mCellPairs[mvMatchPairs[i].first] == mvMatchPairs[i].second)
374:                mvbInlierMask[i] = true;
bug xfeatures2d

All 4 comments

Can you add some reproducible code and data (e.g. two images saved in a lossless format as png)?

Also, you may want to report the bug in the upstream repository.

I dont have a stand alone exampe for bug reproduction at hand but I think this one can be checked by looking at the code only. I tried to explain the problem above

If this line is under test coverage, they you can try to create Pull Request with patch. CI run automatic tests on it.

This has been fixed in the upstream repository, see this comment.

The code in the upstream repository: https://github.com/JiawangBian/GMS-Feature-Matcher/blob/d7e63bb3b1530a6cb183444a5eb27fb0894d0748/include/gms_matcher.h#L411


@0x23

Can you open a pull request with the according change?

Was this page helpful?
0 / 5 - 0 ratings