Skip to content

node_parameters: reject non-finite values in floating-point range check#3143

Open
bartalor wants to merge 1 commit into
ros2:rollingfrom
bartalor:bar/issue-2898
Open

node_parameters: reject non-finite values in floating-point range check#3143
bartalor wants to merge 1 commit into
ros2:rollingfrom
bartalor:bar/issue-2898

Conversation

@bartalor
Copy link
Copy Markdown

Description

Fixes #2898. __check_double_range accepted +inf, -inf, and NaN for parameters declared with a floating_point_range. Fix guards __are_doubles_equal against non-finite operands and rewrites the bound check so NaN is rejected.

Is this user-facing behavior change?

Yes. set_parameter with +inf, -inf, or NaN on a parameter with a floating_point_range now returns successful=false.

Did you use Generative AI?

Yes — Claude Opus 4.7.

Additional Information

Adds a regression test in test_node.cpp for the three non-finite cases. The new scope block pushes the existing TEST_F over cpplint's 800-line limit, so a // NOLINT(readability/fn_size) is added on its closing brace — same pattern other ROS 2 packages use for this case.

Fix ros2#2898. __check_double_range accepted +inf, -inf, and NaN for a
declared floating_point_range. Two causes:

1. The boundary fast path used __are_doubles_equal, whose ULP-tolerance
   arithmetic degenerates on non-finite operands (e.g. it claims +inf
   equals any finite boundary), so +inf and -inf slipped past.
2. The bound check (value < from) || (value > to) is false on both
   sides for NaN, so NaN slipped past.

Fix:

- Guard __are_doubles_equal: if either operand is non-finite, fall
  back to exact ==.
- Rewrite the bound check as !(value >= from && value <= to), which
  rejects NaN.

Adds a regression test for +inf, -inf, and NaN.

Signed-off-by: Bar <bartalor@gmail.com>
{node->remove_pre_set_parameters_callback(handler.get());}); // always reset
}
}
} // NOLINT(readability/fn_size)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test function has been growing for a while.
i understand that this is not for this PR's job to refactor, but we might ask for the new block to be split into its own test fixture instead. that would also be cleaner because the test name (set_parameter_undeclared_parameters_not_allowed) doesn't really describe the new assertion...

@fujitatomoya
Copy link
Copy Markdown
Collaborator

Pulls: #3143
Gist: https://gist.githubusercontent.com/fujitatomoya/e96e535bdc812744725b6237e9eb22e6/raw/ab84ebe82133d581d33d732a722c20660dfc487c/ros2.repos
BUILD args: --packages-above-and-dependencies rclcpp
TEST args: --packages-above rclcpp
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/19255

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Faulty boundary condition check in dynamic parameter update of floating point parameters

2 participants