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

Handle too large QoS queue depths. #457

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions rmw_fastrtps_shared_cpp/src/qos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,10 @@ bool fill_entity_qos_from_profile(
return false;
}

if (qos_policies.depth != RMW_QOS_POLICY_DEPTH_SYSTEM_DEFAULT) {
history_qos.depth = static_cast<int32_t>(qos_policies.depth);
}

// ensure the history depth is at least the requested queue size
assert(history_qos.depth >= 0);
if (
eprosima::fastrtps::KEEP_LAST_HISTORY_QOS == history_qos.kind &&
qos_policies.depth != RMW_QOS_POLICY_DEPTH_SYSTEM_DEFAULT &&
static_cast<size_t>(history_qos.depth) < qos_policies.depth)
{
if (qos_policies.depth > static_cast<size_t>((std::numeric_limits<int32_t>::max)())) {
Expand Down
55 changes: 53 additions & 2 deletions rmw_fastrtps_shared_cpp/test/test_rmw_qos_to_dds_attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <limits>
#include <tuple>

#include "gtest/gtest.h"
Expand Down Expand Up @@ -94,7 +95,32 @@ TEST_F(GetDataReaderQoSTest, nominal_conversion) {
EXPECT_EQ(
eprosima::fastrtps::KEEP_LAST_HISTORY_QOS,
subscriber_attributes_.topic.historyQos.kind);
EXPECT_EQ(10, subscriber_attributes_.topic.historyQos.depth);
EXPECT_GE(10, subscriber_attributes_.topic.historyQos.depth);
}

TEST_F(GetDataReaderQoSTest, large_depth_conversion) {
size_t depth = subscriber_attributes_.topic.historyQos.depth + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the general type of depth here? Are you relying on integer overflowing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifically, "signed integer overflowing"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type is size_t for rmw and int32_t for fastrtps. This isn't relying on overflow (which are UB in C, IIRC), simply ensuring the configured depth is larger than the one already configured.

I don't think there's a practical risk of overflow here anyways, unless we start running ROS 2 on 16 bits architectures or eProsima starts using std::numeric_limits<int32_t>::max() as default depth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I understand better what's being tested.

qos_profile_.depth = depth;
qos_profile_.history = RMW_QOS_POLICY_HISTORY_KEEP_LAST;

EXPECT_TRUE(get_datareader_qos(qos_profile_, subscriber_attributes_));

EXPECT_EQ(
eprosima::fastrtps::KEEP_LAST_HISTORY_QOS,
subscriber_attributes_.topic.historyQos.kind);
EXPECT_LE(depth, static_cast<size_t>(subscriber_attributes_.topic.historyQos.depth));

using depth_type = decltype(subscriber_attributes_.topic.historyQos.depth);
constexpr size_t max_depth = static_cast<size_t>(std::numeric_limits<depth_type>::max());

qos_profile_.depth = max_depth;
EXPECT_TRUE(get_datareader_qos(qos_profile_, subscriber_attributes_));
EXPECT_LE(depth, static_cast<size_t>(subscriber_attributes_.topic.historyQos.depth));

if (max_depth < std::numeric_limits<size_t>::max()) {
qos_profile_.depth = max_depth + 1;
EXPECT_FALSE(get_datareader_qos(qos_profile_, subscriber_attributes_));
}
}

using eprosima::fastrtps::PublisherAttributes;
Expand Down Expand Up @@ -167,5 +193,30 @@ TEST_F(GetDataWriterQoSTest, nominal_conversion) {
EXPECT_EQ(
eprosima::fastrtps::KEEP_LAST_HISTORY_QOS,
publisher_attributes_.topic.historyQos.kind);
EXPECT_EQ(10, publisher_attributes_.topic.historyQos.depth);
EXPECT_GE(10, publisher_attributes_.topic.historyQos.depth);
}

TEST_F(GetDataWriterQoSTest, large_depth_conversion) {
size_t depth = publisher_attributes_.topic.historyQos.depth + 1;
qos_profile_.depth = depth;
qos_profile_.history = RMW_QOS_POLICY_HISTORY_KEEP_LAST;

EXPECT_TRUE(get_datawriter_qos(qos_profile_, publisher_attributes_));

EXPECT_EQ(
eprosima::fastrtps::KEEP_LAST_HISTORY_QOS,
publisher_attributes_.topic.historyQos.kind);
EXPECT_LE(depth, static_cast<size_t>(publisher_attributes_.topic.historyQos.depth));

using depth_type = decltype(publisher_attributes_.topic.historyQos.depth);
constexpr size_t max_depth = static_cast<size_t>(std::numeric_limits<depth_type>::max());

qos_profile_.depth = max_depth;
EXPECT_TRUE(get_datawriter_qos(qos_profile_, publisher_attributes_));
EXPECT_LE(depth, static_cast<size_t>(publisher_attributes_.topic.historyQos.depth));

if (max_depth < std::numeric_limits<size_t>::max()) {
qos_profile_.depth = max_depth + 1;
EXPECT_FALSE(get_datawriter_qos(qos_profile_, publisher_attributes_));
}
}