Skip to content

Commit

Permalink
Check for range_max of laserscan in updateFilter to avoid a implicit …
Browse files Browse the repository at this point in the history
…overflow crash. (ros-navigation#3276)

* Update amcl_node.cpp

* fit the code style

* fit code style
  • Loading branch information
Cryst4L9527 authored and Andrew Lycas committed Feb 23, 2023
1 parent c7cc858 commit 6d01773
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nav2_amcl/src/amcl_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,15 @@ bool AmclNode::updateFilter(
get_logger(), "Laser %d angles in base frame: min: %.3f inc: %.3f", laser_index, angle_min,
angle_increment);

// Check the validity of range_max, must > 0.0
if (laser_scan->range_max <= 0.0) {
RCLCPP_WARN(
get_logger(), "wrong range_max of laser_scan data: %f. The message could be malformed."
" Ignore this message and stop updating.",
laser_scan->range_max);
return false;
}

// Apply range min/max thresholds, if the user supplied them
if (laser_max_range_ > 0.0) {
ldata.range_max = std::min(laser_scan->range_max, static_cast<float>(laser_max_range_));
Expand Down

0 comments on commit 6d01773

Please sign in to comment.