Skip to content

Commit ffd9ad9

Browse files
committed
feature2d: fix crash in AKAZE when using KAZE descriptors
* out-of-bound access in Get_MSURF_Descriptor_64 * this happened reliably when running on provided keypoints (not computed by the same instance)
1 parent eb99617 commit ffd9ad9

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

modules/features2d/src/kaze/AKAZEFeatures.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,19 +1055,28 @@ void MSURF_Descriptor_64_Invoker::Get_MSURF_Descriptor_64(const KeyPoint& kpt, f
10551055
y2 = fRound(sample_y + 0.5f);
10561056
x2 = fRound(sample_x + 0.5f);
10571057

1058+
// fix crash: indexing with out-of-bounds index, this might happen near the edges of image
1059+
// clip values so they fit into the image
1060+
const MatSize& size = evolution[level].Lx.size;
1061+
y1 = min(max(0, y1), size[0] - 1);
1062+
x1 = min(max(0, x1), size[1] - 1);
1063+
y2 = min(max(0, y2), size[0] - 1);
1064+
x2 = min(max(0, x2), size[1] - 1);
1065+
CV_DbgAssert(evolution[level].Lx.size == evolution[level].Ly.size);
1066+
10581067
fx = sample_x - x1;
10591068
fy = sample_y - y1;
10601069

1061-
res1 = *(evolution[level].Lx.ptr<float>(y1)+x1);
1062-
res2 = *(evolution[level].Lx.ptr<float>(y1)+x2);
1063-
res3 = *(evolution[level].Lx.ptr<float>(y2)+x1);
1064-
res4 = *(evolution[level].Lx.ptr<float>(y2)+x2);
1070+
res1 = *(evolution[level].Lx.ptr<float>(y1, x1));
1071+
res2 = *(evolution[level].Lx.ptr<float>(y1, x2));
1072+
res3 = *(evolution[level].Lx.ptr<float>(y2, x1));
1073+
res4 = *(evolution[level].Lx.ptr<float>(y2, x2));
10651074
rx = (1.0f - fx)*(1.0f - fy)*res1 + fx*(1.0f - fy)*res2 + (1.0f - fx)*fy*res3 + fx*fy*res4;
10661075

1067-
res1 = *(evolution[level].Ly.ptr<float>(y1)+x1);
1068-
res2 = *(evolution[level].Ly.ptr<float>(y1)+x2);
1069-
res3 = *(evolution[level].Ly.ptr<float>(y2)+x1);
1070-
res4 = *(evolution[level].Ly.ptr<float>(y2)+x2);
1076+
res1 = *(evolution[level].Ly.ptr<float>(y1, x1));
1077+
res2 = *(evolution[level].Ly.ptr<float>(y1, x2));
1078+
res3 = *(evolution[level].Ly.ptr<float>(y2, x1));
1079+
res4 = *(evolution[level].Ly.ptr<float>(y2, x2));
10711080
ry = (1.0f - fx)*(1.0f - fy)*res1 + fx*(1.0f - fy)*res2 + (1.0f - fx)*fy*res3 + fx*fy*res4;
10721081

10731082
// Get the x and y derivatives on the rotated axis

0 commit comments

Comments
 (0)