Skip to content

Commit 0805a62

Browse files
authored
[ML] Fix out-of-bounds read (#507)
Backport #504
1 parent 3006237 commit 0805a62

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

include/maths/COutliers.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ class CLof final : public CNearestNeighbourMethod<POINT, NEAREST_NEIGHBOURS> {
303303

304304
std::size_t i{point.annotation()};
305305
this->lookup().nearestNeighbours(this->k() + 1, point, neighbours);
306+
307+
if (neighbours.size() < 2) {
308+
return;
309+
}
310+
306311
std::size_t a(point == neighbours[0] ? 1 : 0);
307312
std::size_t b{std::min(this->k() + a - 1, neighbours.size() + a - 2)};
308313

@@ -333,8 +338,10 @@ class CLof final : public CNearestNeighbourMethod<POINT, NEAREST_NEIGHBOURS> {
333338
double distance{las::distance(point_, neighbour)};
334339
reachability_.add(std::max(kdistance, distance));
335340
}
336-
double reachability{
337-
std::max(CBasicStatistics::mean(reachability_), min[0])};
341+
double reachability{CBasicStatistics::mean(reachability_)};
342+
if (min.count() > 0) {
343+
reachability = std::max(reachability, min[0]);
344+
}
338345

339346
point_(j) = point(j);
340347

0 commit comments

Comments
 (0)