ros / roscpp_core

ros distribution sandbox
88 stars 116 forks source link

Misaligned address for type 'double', in serialization.h, causing runtime error. #96

Closed zhoulaifu closed 5 years ago

zhoulaifu commented 5 years ago

I am testing ROS with gcc's ubsan, a sanitizer for detecting undefined behavior. Below is an issue ubsan found in serialization.h.

/opt/ros/kinetic/include/ros/serialization.h:234:5: runtime error: store to misaligned address 0x60600000aca4 for type 'double', which requires 8 byte alignment
0x60600000aca4: note: pointer points here
  30 00 00 00 be be be be  be be be be be be be be  be be be be be be be be  be be be be be be be be
              ^ 

The issue was detected when I tested turtlesim. To reproduce the issue, compile turtlesim with '-fsantize=ubsan. Then, run rosrun turtlesim turtlesim_node in one terminal, and rosrun turtlesim draw_square in another terminal, and then you will get the runtime error and see the message above. Please let me know, if you need more details for reproducing the error message.

Many times misalignment is only a minor issue or even by design, but I am not sure if it is the case here, given that the misalignment occurs in the core of ROS.

gavanderhoorn commented 5 years ago

Could this be architecture specific?

zhoulaifu commented 5 years ago

Possibly.

$ uname -a
Linux ubuntu 4.15.0-39-generic #42~16.04.1-Ubuntu SMP Wed Oct 24 17:09:54 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
hannob commented 5 years ago

I'm unable to reproduce this in melodic and looking at the serialization.h file it looks very different. I believe this code has been refactored and the issue got fixed indirectly by that.

This is an alignment issue, meaning that a variable is stored or accessed at an unaligned memory address. Correct C code should not store an 8 byte variable at a memory address not divisible by 8.

dirk-thomas commented 5 years ago

@zhoulaifu The line number in your error message doesn't match the current code in the repository. Please try to reproduce the problem with the latest code and comment if you are still seeing the problem and if yes, include updated information.

I'm unable to reproduce this in melodic and looking at the serialization.h file it looks very different.

@hannob This repository uses the same branch for Kinetic as well as Melodic.

zhoulaifu commented 5 years ago

Which version of the repo and which distro would you want me to check? FYI, the error message above was from kinetic.

dirk-thomas commented 5 years ago

As mentioned above: the line number in the error message doesn't match the code on the default branch so you might be using an older version. Please post the version number of the package you are using.

Please try to:

zhoulaifu commented 5 years ago

The issue disappears when I have updated the package ros_kinetic_desktop_full to the latest version. Thank you, @dirk-thomas.