-
Notifications
You must be signed in to change notification settings - Fork 126
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
Length of size limited string is not checked #637
Comments
https://github.com/ros2/rclcpp/issues/1827 Signed-off-by: Tomoya Fujita <[email protected]>
confirmed with mainline ros2/ros2@4a36f31, the following is reproducible colcon workspace project, https://github.com/fujitatomoya/ros2_test_prover.
|
I don't know how accurate this comment is, but from // TODO(mikaelarguedas) reenable this test when bounded strings enforce length
TEST(Test_messages, DISABLED_Test_bounded_strings) {
rosidl_generator_cpp::msg::Strings message;
TEST_STRING_FIELD_ASSIGNMENT(message, bounded_string_value, "", "Deep into")
std::string tooLongString = std::string("Too long string");
message.bounded_string_value = tooLongString;
tooLongString.resize(BOUNDED_STRING_LENGTH);
ASSERT_STREQ(tooLongString.c_str(), message.string_value.c_str());
} It seems like bounded length string support has not been fully implemented? I see the difficulty of course, since |
As aprotyas said, bounded length string isn't supported in current implementation. rosidl/rosidl_generator_cpp/resource/msg__struct.hpp.em Lines 238 to 242 in 0ac4130
Generated code as below using _size_limited_string_type =
std::basic_string<char, std::char_traits<char>, typename std::allocator_traits<ContainerAllocator>::template rebind_alloc<char>>;
_size_limited_string_type size_limited_string; size_limited_string is type For current implementation, user only can know whether string is bounded. rosidl/rosidl_generator_cpp/resource/msg__traits.hpp.em Lines 265 to 287 in 0ac4130
Generated code as below template<>
struct has_bounded_size<interfaces_bug::msg::StringLengthTest>
: std::integral_constant<bool, true> {}; |
I think this issue should be transferred to ros2/rosidl - that repository houses the packages which generate/support message structures/traits. |
Indeed, a |
If no one is working on this issue, I would like to contribute to it. |
This was on my backlog but feel free to proceed! |
Oh, it seems better if you (@aprotyas) fix this issue. (To review my PR might cost you much more time, 😆 ) |
Bug report
Required Info:
Steps to reproduce issue
Create a message type (
StringLengthTest.msg
) with size limited string field:Publish a message with a lengthier string:
Expected behavior
Exception of type
std::length_error
.Actual behavior
Message is published and received in full by an rclcpp subscriber, i.e., no error and no truncation.
Side note: an rclpy subscriber does throw an error:
The text was updated successfully, but these errors were encountered: