Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rosidl_typesupport_introspection_cpp potentially unsafe #320

Closed
Karsten1987 opened this issue Nov 14, 2018 · 0 comments · Fixed by #321
Closed

rosidl_typesupport_introspection_cpp potentially unsafe #320

Karsten1987 opened this issue Nov 14, 2018 · 0 comments · Fixed by #321

Comments

@Karsten1987
Copy link
Contributor

Bug report

Required Info:

  • Operating System:
    • All
  • Installation type:
    • source
  • Version or commit hash:
    • master
  • DDS implementation:
    • N/A
  • Client library (if applicable):
    • rosidl_typesupport_introspection_cpp

Steps to reproduce issue

The code in question is here:

@(field.type.pkg_name)::msg::@(field.type.type) * member =
reinterpret_cast<@(field.type.pkg_name)::msg::@(field.type.type) *>(untyped_member);

Fixed size arrays are getting resolved to std::array<T, N>, however the getter function inside the introspection code access the elements via a reinterpret_cast<T *>, which is potentially unsafe to do.
More info here:
https://stackoverflow.com/questions/39376813/is-the-stdarray-bit-compatible-with-the-old-c-array/39379359#39379359

This came out during dev time of rosbag2:
ros2/rosbag2#56 (comment)


Expected behavior

Does it make sense to cast it to an std::array<T, N> before accessing the element?

Actual behavior

Cast to T *

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 a pull request may close this issue.

1 participant