micro-ROS / micro-ROS-Agent

ROS 2 package using Micro XRCE-DDS Agent.
Apache License 2.0
100 stars 57 forks source link

Deserializing error for string type #234

Open hr-ti opened 3 weeks ago

hr-ti commented 3 weeks ago

Describe the bug String types in service types cause microROS on the MCU side to fail in the executor due to a deserializing error. Running it through a debugger it fails in ucdr_deserialize_sequence_header when parsing the nested message type.

Service calls with non-string types work as expected. I've verified it's not a buffer overflow since the buffer size >> bytes received. There is also no packet corruption in UDP traffic, the dest packet and src packet match 1:1.

To Reproduce Steps to reproduce the behaviour:

  1. On MCU, init service with service type that has a string type
  2. On host side, call service

Expected behaviour The MCU accepts the service call and handles accordingly.

Actual behaviour Executor fails due to deserialization error.

System information (please complete the following information):

hr-ti commented 3 weeks ago

Seems like this is an error with the nested message type's string member. As it fails in ucdr_deserialize_sequence_header, the length of the string member is greater than the capacity in rosidl_runtime_c__String, which is always 0.

Since there's no issue with UDP comms, this could be due to an error in generating the string type from the agent side.

hr-ti commented 2 weeks ago

This actually applies to any sequence type, like a byte array. Since capacity is always 0, any populated sequence simply just fails

gavanderhoorn commented 2 weeks ago

Edit: apologies, confused capacity with size.

re: capacity: how do you initialise your message/service structs? Are you using the appropriate _init(..)/_fini(..) pairs or are you using micro_ros_utilities?