[ros2 turtlesim] turtle.cpp needs to validate float32/float64 input variables
squizz617 opened this issue · 1 comments
squizz617 commented
There are many places in the code that assume control inputs (i.e., x, y, and theta) are valid floating point numbers. As a result, when one of nan, -nan, inf or -inf is given, the turtle's position becomes infeasible (e.g., x being nan), sometimes even become rendering it uncontrollable.
- Case 1:
teleport_absoluteservice- In
Turtle::update(), the requestedxis directly used to set position (pos_.setX(req.pos.x());). - When
nanor-nanis provided, turtle'sxposition becomesnan. - Requests with
thetaset tonanorinfmakex,y, andthetaof the turtle's posenan, removing the turtle from the frame.
- In
- Case 2:
teleport_relativeservice- Similarly, if
linearand/orangularofteleport_relativerequest is set tonanorinf, turtle's position becomes infeasible.
- Similarly, if
- Case 3:
rotate_absoluteaction- Sending goal with
thetaset tonanorinfcan have the turtle rotate indefinitely, asremainingbecomes eithernanor-nan. - This forces
ang_vel_to become 1.0 after executing the following statement:ang_vel_ = remaining < 0.0 ? -1.0 : 1.0;, asnan < 0.0always evaluates toFalse.
- Sending goal with
- Case 4:
cmd_veltopiclinear.x,linear.y, andangular.zare not sanitized before being used. Similar to the previous cases,x,yand/orthetaof turtle's pose are easily set tonan.
I suggest adding checks before using these variables, e.g., std::isnan and std::isinf, to prevent unexpected input values from polluting the turtle's state.
audrow commented
Hi @squizz617, thanks for making this issue. Feel free to make a PR with some or all of these fixes. If you do, you can @ me for a review.