Skip to content

Commit 2c53895

Browse files
committed
features2d: fix crash in AKAZE
* out-of-bound reads near the image edge * same as the bug in KAZE descriptors
1 parent c97efd3 commit 2c53895

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

modules/features2d/src/kaze/AKAZEFeatures.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,20 @@ void MLDB_Full_Descriptor_Invoker::MLDB_Fill_Values(float* values, int sample_st
12351235
int y1 = fRound(sample_y);
12361236
int x1 = fRound(sample_x);
12371237

1238-
float ri = *(evolution[level].Lt.ptr<float>(y1)+x1);
1238+
// fix crash: indexing with out-of-bounds index, this might happen near the edges of image
1239+
// clip values so they fit into the image
1240+
const MatSize& size = evolution[level].Lt.size;
1241+
CV_DbgAssert(size == evolution[level].Lx.size &&
1242+
size == evolution[level].Ly.size);
1243+
y1 = min(max(0, y1), size[0] - 1);
1244+
x1 = min(max(0, x1), size[1] - 1);
1245+
1246+
float ri = *(evolution[level].Lt.ptr<float>(y1, x1));
12391247
di += ri;
12401248

12411249
if(chan > 1) {
1242-
float rx = *(evolution[level].Lx.ptr<float>(y1)+x1);
1243-
float ry = *(evolution[level].Ly.ptr<float>(y1)+x1);
1250+
float rx = *(evolution[level].Lx.ptr<float>(y1, x1));
1251+
float ry = *(evolution[level].Ly.ptr<float>(y1, x1));
12441252
if (chan == 2) {
12451253
dx += sqrtf(rx*rx + ry*ry);
12461254
}

0 commit comments

Comments
 (0)