Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix out of bounds for heap-array in statistical outlier filter #5502

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ pcl::StatisticalOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
searcher_->setInputCloud (input_);

// The arrays to be used
Indices nn_indices (mean_k_);
std::vector<float> nn_dists (mean_k_);
const int searcher_k = mean_k_ + 1; // Find one more, since results include the query point.
Indices nn_indices (searcher_k);
std::vector<float> nn_dists (searcher_k);
std::vector<float> distances (indices_->size ());
indices.resize (indices_->size ());
removed_indices_->resize (indices_->size ());
Expand All @@ -79,7 +80,7 @@ pcl::StatisticalOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)
}

// Perform the nearest k search
if (searcher_->nearestKSearch ((*indices_)[iii], mean_k_ + 1, nn_indices, nn_dists) == 0)
if (searcher_->nearestKSearch ((*indices_)[iii], searcher_k, nn_indices, nn_dists) == 0)
{
distances[iii] = 0.0;
PCL_WARN ("[pcl::%s::applyFilter] Searching for the closest %d neighbors failed.\n", getClassName ().c_str (), mean_k_);
Expand All @@ -88,7 +89,7 @@ pcl::StatisticalOutlierRemoval<PointT>::applyFilterIndices (Indices &indices)

// Calculate the mean distance to its neighbors
double dist_sum = 0.0;
for (int k = 1; k < mean_k_ + 1; ++k) // k = 0 is the query point
for (int k = 1; k < searcher_k; ++k) // k = 0 is the query point
dist_sum += sqrt (nn_dists[k]);
distances[iii] = static_cast<float> (dist_sum / mean_k_);
valid_distances++;
Expand Down