You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OS Version: Ubuntu 24.04
rviz version: ros2 jazzy
Compiler name and version number: Ubuntu clang version 18.1.3
Source or binary build?
source build
build options: --mixin asan-gcc
Description
The function rviz_default_plugins::ogreQuaternionAngularDistance does not validate the input quaternions. When invalid quaternions are passed in (e.g., quaternions with zero norm such as (0, 0, 0, 0)), the function performs the computation and silently returns 0.0f without throwing any exception or error.
This behavior may conceal logical errors in upstream code and negatively impacts the robustness and safety of the system.
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from QuaternionHelper
[ RUN ] QuaternionHelper.ogreQuaternionAngularDistance_handles_zero_product_w
/home/shangzh/ros2_jazzy/src/ros2/rviz/rviz_default_plugins/test/rviz_default_plugins/displays/odometry/quaternion_helper_test.cpp:11: Failure
Expected: rviz_default_plugins::ogreQuaternionAngularDistance(quaternion1, quaternion2) throws an exception of type std::runtime_error.
Actual: it throws nothing.
[ FAILED ] QuaternionHelper.ogreQuaternionAngularDistance_handles_zero_product_w (0 ms)
[----------] 1 test from QuaternionHelper (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] QuaternionHelper.ogreQuaternionAngularDistance_handles_zero_product_w
1 FAILED TEST
Expected behavior
When the function receives invalid quaternions (e.g., with zero or near-zero norm), it should detect the invalid input and throw a std::runtime_error to notify the caller that the input is not valid.
Actual behavior
Even when both input quaternions are (0.0f, 0.0f, 0.0f, 0.0f), the function completes execution and returns 0.0f, without any warning or exception. This violates basic input validation practices and misleads the user into believing the computation was successful.
Additional information
Suggested Fix
floatogreQuaternionAngularDistance(Ogre::Quaternion first, Ogre::Quaternion second)
{
constfloat epsilon = 1e-6f;
if (first.norm() < epsilon || second.norm() < epsilon) {
throwstd::runtime_error("Invalid quaternion: norm is zero or too small");
}
Ogre::Quaternion product = first * Ogre::Quaternion(second.w, -second.x, -second.y, -second.z);
float imaginary_norm =
sqrtf(powf(product.x, 2.0f) + powf(product.y, 2.0f) + powf(product.z, 2.0f));
return2.0f * atan2f(imaginary_norm, sqrtf(powf(product.w, 2.0f)));
}
The text was updated successfully, but these errors were encountered:
Operating System:
Linux shangzh-VMware-Virtual-Platform 6.11.0-19-generic #19~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Feb 17 11:51:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
ROS version or commit hash:
ros 2 jazzy
RMW implementation (if applicable):
No response
RMW Configuration (if applicable):
No response
Client library (if applicable):
rviz
'ros2 doctor --report' output
ros2 doc --report
Steps to reproduce issue
Environment
OS Version: Ubuntu 24.04
rviz version: ros2 jazzy
Compiler name and version number: Ubuntu clang version 18.1.3
Source or binary build?
source build
build options: --mixin asan-gcc
Description
The function rviz_default_plugins::ogreQuaternionAngularDistance does not validate the input quaternions. When invalid quaternions are passed in (e.g., quaternions with zero norm such as (0, 0, 0, 0)), the function performs the computation and silently returns 0.0f without throwing any exception or error.
This behavior may conceal logical errors in upstream code and negatively impacts the robustness and safety of the system.
Test Case
Output
Expected behavior
When the function receives invalid quaternions (e.g., with zero or near-zero norm), it should detect the invalid input and throw a std::runtime_error to notify the caller that the input is not valid.
Actual behavior
Even when both input quaternions are (0.0f, 0.0f, 0.0f, 0.0f), the function completes execution and returns 0.0f, without any warning or exception. This violates basic input validation practices and misleads the user into believing the computation was successful.
Additional information
Suggested Fix
The text was updated successfully, but these errors were encountered: