From d1b63ebe6adae1c86c86ca6ec6e4f9e825b4fa13 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 12:54:49 +0100 Subject: [PATCH] Be less strict with parameter lengths (#5225) (#5248) * Be less strict with parameter lengths (#5225) * Refs #21537. Add regression test for interoperability issue. Signed-off-by: Miguel Company * Refs #21537. Add regression test for big parameters. Signed-off-by: Miguel Company * Refs #21537. Fix builtin deserialization length checks. Signed-off-by: Miguel Company * Refs #21537. Special cases in test. Signed-off-by: Miguel Company * Refs #21537. Extend test to full non-custom range. Signed-off-by: Miguel Company * Refs #21537. Extend parameter size to 64K. Signed-off-by: Miguel Company * Refs #21537. Uncrustify. Signed-off-by: Miguel Company * Refs #21638. Fix windows warning. Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company (cherry picked from commit 7b111f91119710b77f1d75bc772b976627e1e814) # Conflicts: # src/cpp/fastdds/core/policy/ParameterSerializer.hpp # test/unittest/rtps/builtin/BuiltinDataSerializationTests.cpp * Fix conflicts Signed-off-by: Miguel Company --------- Signed-off-by: Miguel Company Co-authored-by: Miguel Company --- .../core/policy/ParameterSerializer.hpp | 32 +- .../core/policy/QosPoliciesSerializer.hpp | 32 +- .../builtin/BuiltinDataSerializationTests.cpp | 509 ++++++++++++++++++ 3 files changed, 541 insertions(+), 32 deletions(-) diff --git a/src/cpp/fastdds/core/policy/ParameterSerializer.hpp b/src/cpp/fastdds/core/policy/ParameterSerializer.hpp index eec40a9d804..f34658b4312 100644 --- a/src/cpp/fastdds/core/policy/ParameterSerializer.hpp +++ b/src/cpp/fastdds/core/policy/ParameterSerializer.hpp @@ -251,7 +251,7 @@ inline bool ParameterSerializer::read_content_from_cdr_messa fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_LOCATOR_LENGTH) + if (parameter_length < PARAMETER_LOCATOR_LENGTH) { return false; } @@ -273,7 +273,7 @@ inline bool ParameterSerializer::read_content_from_cdr_message( fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_KEY_HASH_LENGTH) + if (parameter_length < PARAMETER_KEY_HASH_LENGTH) { return false; } @@ -343,7 +343,7 @@ inline bool ParameterSerializer::read_content_from_cdr_message( fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_PORT_LENGTH) + if (parameter_length < PARAMETER_PORT_LENGTH) { return false; } @@ -367,7 +367,7 @@ inline bool ParameterSerializer::read_content_from_cdr_message( fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_GUID_LENGTH) + if (parameter_length < PARAMETER_GUID_LENGTH) { return false; } @@ -394,7 +394,7 @@ inline bool ParameterSerializer::read_content_from_c fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_PROTOCOL_LENGTH) + if (parameter_length < PARAMETER_PROTOCOL_LENGTH) { return false; } @@ -422,7 +422,7 @@ inline bool ParameterSerializer::read_content_from_cdr_mess fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_VENDOR_LENGTH) + if (parameter_length < PARAMETER_VENDOR_LENGTH) { return false; } @@ -447,7 +447,7 @@ inline bool ParameterSerializer::read_content_from_cdr_me fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_IP4_LENGTH) + if (parameter_length < PARAMETER_IP4_LENGTH) { return false; } @@ -473,7 +473,7 @@ inline bool ParameterSerializer::read_content_from_cdr_message( fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_BOOL_LENGTH) + if (parameter_length < PARAMETER_BOOL_LENGTH) { return false; } @@ -501,7 +501,7 @@ inline bool ParameterSerializer::read_content_from_cdr_me fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_STATUS_INFO_LENGTH) + if (parameter_length < PARAMETER_STATUS_INFO_LENGTH) { return false; } @@ -530,7 +530,7 @@ inline bool ParameterSerializer::read_content_from_cdr_message fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_COUNT_LENGTH) + if (parameter_length < PARAMETER_COUNT_LENGTH) { return false; } @@ -552,7 +552,7 @@ inline bool ParameterSerializer::read_content_from_cdr_mess fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_ENTITYID_LENGTH) + if (parameter_length < PARAMETER_ENTITYID_LENGTH) { return false; } @@ -576,7 +576,7 @@ inline bool ParameterSerializer::read_content_from_cdr_message( fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_TIME_LENGTH) + if (parameter_length < PARAMETER_TIME_LENGTH) { return false; } @@ -604,7 +604,7 @@ inline bool ParameterSerializer::read_content_fro fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_BUILTINENDPOINTSET_LENGTH) + if (parameter_length < PARAMETER_BUILTINENDPOINTSET_LENGTH) { return false; } @@ -761,7 +761,7 @@ inline bool ParameterSerializer::read_content_from_cd fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_SAMPLEIDENTITY_LENGTH) + if (parameter_length < PARAMETER_SAMPLEIDENTITY_LENGTH) { return false; } @@ -1039,7 +1039,7 @@ inline bool ParameterSerializer::read_conten fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH) + if (parameter_length < PARAMETER_PARTICIPANT_SECURITY_INFO_LENGTH) { return false; } @@ -1065,7 +1065,7 @@ inline bool ParameterSerializer::read_content_f fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH) + if (parameter_length < PARAMETER_ENDPOINT_SECURITY_INFO_LENGTH) { return false; } diff --git a/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp b/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp index 3c7830c253b..9f9b8c2e83d 100644 --- a/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp +++ b/src/cpp/fastdds/core/policy/QosPoliciesSerializer.hpp @@ -97,7 +97,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_me fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_KIND_LENGTH) + if (parameter_length < PARAMETER_KIND_LENGTH) { return false; } @@ -126,7 +126,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_mess fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_TIME_LENGTH) + if (parameter_length < PARAMETER_TIME_LENGTH) { return false; } @@ -155,7 +155,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_TIME_LENGTH) + if (parameter_length < PARAMETER_TIME_LENGTH) { return false; } @@ -190,7 +190,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_me fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH) + if (parameter_length < PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH) { return false; } @@ -229,7 +229,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_m fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH) + if (parameter_length < PARAMETER_KIND_LENGTH + PARAMETER_TIME_LENGTH) { return false; } @@ -263,7 +263,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_mes fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_KIND_LENGTH) + if (parameter_length < PARAMETER_KIND_LENGTH) { return false; } @@ -292,7 +292,7 @@ inline bool QosPoliciesSerializer::read_content_from_ fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_KIND_LENGTH) + if (parameter_length < PARAMETER_KIND_LENGTH) { return false; } @@ -323,7 +323,7 @@ inline bool QosPoliciesSerializer::read_content_from_cd fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != 12) + if (parameter_length < 12) { return false; } @@ -357,7 +357,7 @@ inline bool QosPoliciesSerializer::read_content_from_c fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_TIME_LENGTH) + if (parameter_length < PARAMETER_TIME_LENGTH) { return false; } @@ -397,7 +397,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_ fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_PRESENTATION_LENGTH) + if (parameter_length < PARAMETER_PRESENTATION_LENGTH) { return false; } @@ -516,7 +516,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_messa fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_KIND_LENGTH + 4) + if (parameter_length < PARAMETER_KIND_LENGTH + 4) { return false; } @@ -553,7 +553,7 @@ inline bool QosPoliciesSerializer::read_content_from fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_TIME_LENGTH + PARAMETER_KIND_LENGTH + 16) + if (parameter_length < PARAMETER_TIME_LENGTH + PARAMETER_KIND_LENGTH + 16) { return false; } @@ -588,7 +588,7 @@ inline bool QosPoliciesSerializer::read_content_from_cdr_mess fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_TIME_LENGTH) + if (parameter_length < PARAMETER_TIME_LENGTH) { return false; } @@ -615,7 +615,7 @@ inline bool QosPoliciesSerializer::read_content_from fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != 4) + if (parameter_length < 4) { return false; } @@ -638,7 +638,7 @@ inline bool QosPoliciesSerializer::read_content_from fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != 4) + if (parameter_length < 4) { return false; } @@ -800,7 +800,7 @@ inline bool QosPoliciesSerializer::read_content_fr fastrtps::rtps::CDRMessage_t* cdr_message, const uint16_t parameter_length) { - if (parameter_length != PARAMETER_BOOL_LENGTH) + if (parameter_length < PARAMETER_BOOL_LENGTH) { return false; } diff --git a/test/unittest/rtps/builtin/BuiltinDataSerializationTests.cpp b/test/unittest/rtps/builtin/BuiltinDataSerializationTests.cpp index a46a46a802f..fe7c9b81b79 100644 --- a/test/unittest/rtps/builtin/BuiltinDataSerializationTests.cpp +++ b/test/unittest/rtps/builtin/BuiltinDataSerializationTests.cpp @@ -13,6 +13,12 @@ // limitations under the License. #include "fastdds/rtps/messages/CDRMessage.h" + +#include +#include +#include +#include + #include #include @@ -1401,6 +1407,509 @@ TEST(BuiltinDataSerializationTests, null_checks) } } +/*! + * This is a regression test for redmine issue #21537 + * + * It checks that Fast DDS can deserialize DATA(p), DATA(w), and DATA(r) messages captured from InterCom DDS. + */ +TEST(BuiltinDataSerializationTests, interoperability_with_intercomdds) +{ + // DATA(p) + { + // This was captured with wireshark from intercom_dds-3.16.2.0_shape_main_linux taken from + // https://github.com/omg-dds/dds-rtps/releases/tag/v1.2.2024 + octet data_p_buffer[] = + { + // Encapsulation + 0x00, 0x03, 0x00, 0x00, + // Participant GUID + 0x50, 0x00, 0x10, 0x00, + 0x01, 0x05, 0xfa, 0xd5, 0x7a, 0x09, 0x6a, 0x22, 0x84, 0xfb, 0x23, 0xa2, 0x00, 0x00, 0x01, 0xc1, + // Custom (0x8005) + 0x05, 0x80, 0x18, 0x00, + 0x12, 0x00, 0x00, 0x00, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x43, 0x4f, 0x4d, 0x20, 0x33, 0x5f, 0x31, + 0x36, 0x5f, 0x32, 0x5f, 0x30, 0x00, 0x00, 0x00, + // Custom (0x8006) + 0x06, 0x80, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Custom (0x8007) + 0x07, 0x80, 0x0c, 0x00, + 0x01, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, + // Custom (0x8008) + 0x08, 0x80, 0x08, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Custom (0x8009) + 0x09, 0x80, 0x34, 0x00, + 0x2e, 0x00, 0x00, 0x00, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x63, 0x6f, 0x6d, 0x5f, 0x64, 0x64, 0x73, + 0x2d, 0x33, 0x2e, 0x31, 0x36, 0x2e, 0x32, 0x2e, 0x30, 0x5f, 0x73, 0x68, 0x61, 0x70, 0x65, 0x5f, + 0x6d, 0x61, 0x69, 0x6e, 0x5f, 0x6c, 0x69, 0x6e, 0x75, 0x78, 0x20, 0x28, 0x37, 0x30, 0x34, 0x35, + 0x29, 0x00, 0x00, 0x00, + // Domain ID + 0x0f, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Builtin endpoint QoS + 0x77, 0x00, 0x04, 0x00, + 0x01, 0x00, 0x00, 0x00, + // Builtin endpoint set + 0x58, 0x00, 0x04, 0x00, + 0x3f, 0xfc, 0x00, 0x00, + // Protocol version + 0x15, 0x00, 0x04, 0x00, + 0x02, 0x05, 0x00, 0x00, + // Vendor ID + 0x16, 0x00, 0x04, 0x00, + 0x01, 0x05, 0x00, 0x00, + // Default Unicast Locator + 0x31, 0x00, 0x18, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xf5, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xac, 0x1a, 0x9f, 0xd5, + // Default Multicast Locator + 0x48, 0x00, 0x18, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xe9, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xef, 0xff, 0x00, 0x01, + // Metatraffic unicast locator + 0x32, 0x00, 0x18, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xf4, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xac, 0x1a, 0x9f, 0xd5, + // Metatraffic multicast locator + 0x33, 0x00, 0x18, 0x00, + 0x01, 0x00, 0x00, 0x00, 0xe8, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xef, 0xff, 0x00, 0x01, + // Participant lease duration + 0x02, 0x00, 0x08, 0x00, + 0x2c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Sentinel + 0x01, 0x00, 0x00, 0x00 + }; + + CDRMessage_t msg(0); + msg.init(data_p_buffer, static_cast(sizeof(data_p_buffer))); + msg.length = msg.max_size; + + ParticipantProxyData out({}); + EXPECT_NO_THROW(EXPECT_TRUE(out.readFromCDRMessage(&msg, true, network, false))); + } + + // DATA(w) + { + // This was captured with wireshark from intercom_dds-3.16.2.0_shape_main_linux taken from + // https://github.com/omg-dds/dds-rtps/releases/tag/v1.2.2024 + octet data_w_buffer[] = + { + // Encapsulation + 0x00, 0x03, 0x00, 0x00, + // Writer GUID + 0x5a, 0x00, 0x10, 0x00, + 0x01, 0x05, 0xfa, 0xd5, 0x7a, 0x09, 0x6a, 0x22, 0x84, 0xfb, 0x23, 0xa2, 0x00, 0x00, 0x01, 0x02, + // Participant GUID + 0x50, 0x00, 0x10, 0x00, + 0x01, 0x05, 0xfa, 0xd5, 0x7a, 0x09, 0x6a, 0x22, 0x84, 0xfb, 0x23, 0xa2, 0x00, 0x00, 0x01, 0xc1, + // Topic name + 0x05, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x53, 0x71, 0x75, 0x61, 0x72, 0x65, 0x00, 0x00, + // Type name + 0x07, 0x00, 0x10, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x53, 0x68, 0x61, 0x70, 0x65, 0x54, 0x79, 0x70, 0x65, 0x00, 0x00, 0x00, + // Type information + 0x75, 0x00, 0x5c, 0x00, + 0x58, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x50, 0x24, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0xf1, 0xa5, 0x12, 0xf3, 0x95, 0xe2, 0xba, 0xb0, 0xb9, 0xfc, 0x83, 0x8e, 0x08, 0x6e, 0x2c, 0x00, + 0x57, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x10, 0x00, 0x50, 0x24, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xf2, 0x77, 0x32, 0x07, + 0xfb, 0x72, 0x38, 0x6e, 0x0d, 0xdb, 0x0e, 0x1a, 0x2b, 0x4f, 0xbe, 0x00, 0x84, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Topic data + 0x2e, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Data representation + 0x73, 0x00, 0x08, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Property list + 0x59, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Data tags + 0x03, 0x10, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Service instance name + 0x80, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Related entity GUID + 0x81, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // History + 0x40, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + // Custom (0x8030) + 0x30, 0x80, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Sentinel + 0x01, 0x00, 0x00, 0x00 + }; + + CDRMessage_t msg(0); + msg.init(data_w_buffer, static_cast(sizeof(data_w_buffer))); + msg.length = msg.max_size; + + WriterProxyData out(max_unicast_locators, max_multicast_locators); + EXPECT_NO_THROW(EXPECT_TRUE(out.readFromCDRMessage(&msg, network, true))); + } + + // DATA(r) + { + // This was captured with wireshark from intercom_dds-3.16.2.0_shape_main_linux taken from + // https://github.com/omg-dds/dds-rtps/releases/tag/v1.2.2024 + uint8_t data_r_buffer[] = + { + // Encapsulation + 0x00, 0x03, 0x00, 0x00, + // Reader GUID + 0x5a, 0x00, 0x10, 0x00, + 0x01, 0x05, 0x0f, 0xda, 0x14, 0xdd, 0x32, 0x62, 0x74, 0xef, 0x08, 0xeb, 0x00, 0x00, 0x01, 0x07, + // Participant GUID + 0x50, 0x00, 0x10, 0x00, + 0x01, 0x05, 0x0f, 0xda, 0x14, 0xdd, 0x32, 0x62, 0x74, 0xef, 0x08, 0xeb, 0x00, 0x00, 0x01, 0xc1, + // Topic name + 0x05, 0x00, 0x0c, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x53, 0x71, 0x75, 0x61, 0x72, 0x65, 0x00, 0x00, + // Type name + 0x07, 0x00, 0x10, 0x00, + 0x0a, 0x00, 0x00, 0x00, 0x53, 0x68, 0x61, 0x70, 0x65, 0x54, 0x79, 0x70, 0x65, 0x00, 0x00, 0x00, + // Type information + 0x75, 0x00, 0x5c, 0x00, + 0x58, 0x00, 0x00, 0x00, 0x01, 0x10, 0x00, 0x50, 0x24, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, + 0xf1, 0xa5, 0x12, 0xf3, 0x95, 0xe2, 0xba, 0xb0, 0xb9, 0xfc, 0x83, 0x8e, 0x08, 0x6e, 0x2c, 0x00, + 0x57, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x10, 0x00, 0x50, 0x24, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0xf2, 0x77, 0x32, 0x07, + 0xfb, 0x72, 0x38, 0x6e, 0x0d, 0xdb, 0x0e, 0x1a, 0x2b, 0x4f, 0xbe, 0x00, 0x84, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Reliability + 0x1a, 0x00, 0x10, 0x00, + 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9a, 0x99, 0x99, 0x19, 0x00, 0x00, 0x00, 0x00, + // Topic data + 0x2e, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Data representation + 0x73, 0x00, 0x08, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Type consistency + 0x74, 0x00, 0x08, 0x00, + 0x01, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, + // Property list + 0x59, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // Data tags + 0x03, 0x10, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Service instance name + 0x80, 0x00, 0x04, 0x00, + 0x00, 0x00, 0x00, 0x00, + // Related entity GUID + 0x81, 0x00, 0x10, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // History + 0x40, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, + // Sentinel + 0x01, 0x00, 0x00, 0x00 + }; + + CDRMessage_t msg(0); + msg.init(data_r_buffer, static_cast(sizeof(data_r_buffer))); + msg.length = msg.max_size; + + ReaderProxyData out(max_unicast_locators, max_multicast_locators); + EXPECT_NO_THROW(EXPECT_TRUE(out.readFromCDRMessage(&msg, network, true))); + } +} + +/*! + * This is a regression test for redmine issue #21537 + * + * It checks deserialization of builtin data with big parameters. + */ +TEST(BuiltinDataSerializationTests, deserialization_of_big_parameters) +{ + constexpr size_t encapsulation_length = 4; + constexpr size_t guid_length = 20; + constexpr size_t topic_name_length = 16; + constexpr size_t type_name_length = 16; + constexpr size_t parameter_length = 65536; + constexpr size_t sentinel_length = 4; + constexpr size_t total_length = + encapsulation_length + // encapsulation + parameter_length + // Big parameter + guid_length + // Participant GUID + guid_length + // Endpoint GUID + topic_name_length + // Topic name + type_name_length + // Type name + sentinel_length; // Sentinel + std::array buffer{{0}}; + + // Encapsulation (PL_CDR_LE) + size_t pos = 0; + buffer[pos++] = 0x00; + buffer[pos++] = 0x03; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + + // Room for the big parameter + pos += parameter_length; + + // Participant GUID + buffer[pos++] = 0x50; + buffer[pos++] = 0x00; + buffer[pos++] = 0x10; + buffer[pos++] = 0x00; + buffer[pos++] = 0x01; + buffer[pos++] = 0x05; + buffer[pos++] = 0x0f; + buffer[pos++] = 0xda; + buffer[pos++] = 0x14; + buffer[pos++] = 0xdd; + buffer[pos++] = 0x32; + buffer[pos++] = 0x62; + buffer[pos++] = 0x74; + buffer[pos++] = 0xef; + buffer[pos++] = 0x08; + buffer[pos++] = 0xeb; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + buffer[pos++] = 0x01; + buffer[pos++] = 0xc1; + + // Endpoint GUID + buffer[pos++] = 0x5a; + buffer[pos++] = 0x00; + buffer[pos++] = 0x10; + buffer[pos++] = 0x00; + buffer[pos++] = 0x01; + buffer[pos++] = 0x05; + buffer[pos++] = 0x0f; + buffer[pos++] = 0xda; + buffer[pos++] = 0x14; + buffer[pos++] = 0xdd; + buffer[pos++] = 0x32; + buffer[pos++] = 0x62; + buffer[pos++] = 0x74; + buffer[pos++] = 0xef; + buffer[pos++] = 0x08; + buffer[pos++] = 0xeb; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + buffer[pos++] = 0x01; + buffer[pos++] = 0x07; + + // Topic name ("Square") + buffer[pos++] = 0x05; + buffer[pos++] = 0x00; + buffer[pos++] = 0x0c; + buffer[pos++] = 0x00; + buffer[pos++] = 0x07; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + buffer[pos++] = 0x53; + buffer[pos++] = 0x71; + buffer[pos++] = 0x75; + buffer[pos++] = 0x61; + buffer[pos++] = 0x72; + buffer[pos++] = 0x65; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + + // Type name ("MyType") + buffer[pos++] = 0x07; + buffer[pos++] = 0x00; + buffer[pos++] = 0x0c; + buffer[pos++] = 0x00; + buffer[pos++] = 0x07; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + buffer[pos++] = 0x4d; + buffer[pos++] = 0x79; + buffer[pos++] = 0x54; + buffer[pos++] = 0x79; + buffer[pos++] = 0x70; + buffer[pos++] = 0x65; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + + // Sentinel + buffer[pos++] = 0x01; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + buffer[pos++] = 0x00; + + ASSERT_EQ(total_length, pos); + + std::set failed_for_data_p; + std::set failed_for_data_w; + std::set failed_for_data_r; + + // Loop all parameter IDs in the standard range + for (uint16_t pid = 0x2; pid <= 0x7FFF; ++pid) + { + // Clear big parameter + octet zero = 0u; + auto param_begin = buffer.begin() + encapsulation_length; + std::fill(param_begin, param_begin + parameter_length, zero); + + // Set the parameter ID of the big parameter + constexpr uint16_t big_parameter_plength = parameter_length - 4; + buffer[encapsulation_length] = static_cast(pid & 0xFF); + buffer[encapsulation_length + 1] = static_cast((pid >> 8) & 0xFF); + buffer[encapsulation_length + 2] = static_cast(big_parameter_plength & 0xFF); + buffer[encapsulation_length + 3] = static_cast((big_parameter_plength >> 8) & 0xFF); + + // Beware of semantically incorrect parameters + switch (pid) + { + // The protocol version should be 2 + case eprosima::fastdds::dds::PID_PROTOCOL_VERSION: + { + buffer[encapsulation_length + 4] = 0x02; + } + break; + + // The length of some string parameters should be lower than 256 + case eprosima::fastdds::dds::PID_ENTITY_NAME: + case eprosima::fastdds::dds::PID_TYPE_NAME: + case eprosima::fastdds::dds::PID_TOPIC_NAME: + { + buffer[encapsulation_length + 2] = 0xFF; + buffer[encapsulation_length + 3] = 0x00; + } + break; + + // Data parameters should fill the whole parameter + case eprosima::fastdds::dds::PID_USER_DATA: + case eprosima::fastdds::dds::PID_TOPIC_DATA: + case eprosima::fastdds::dds::PID_GROUP_DATA: + { + constexpr uint16_t inner_data_length = big_parameter_plength - 4; + buffer[encapsulation_length + 4] = static_cast(inner_data_length & 0xFF); + buffer[encapsulation_length + 5] = static_cast((inner_data_length >> 8) & 0xFF); + } + break; + + // Custom content for partition + case eprosima::fastdds::dds::PID_PARTITION: + { + // Number of partitions (1) + buffer[encapsulation_length + 4] = 0x01; + buffer[encapsulation_length + 5] = 0x00; + buffer[encapsulation_length + 6] = 0x00; + buffer[encapsulation_length + 7] = 0x00; + // Partition name length (fills the rest of the parameter) + constexpr uint16_t partition_length = big_parameter_plength - 4 - 4; + buffer[encapsulation_length + 8] = static_cast(partition_length & 0xFF); + buffer[encapsulation_length + 9] = static_cast((partition_length >> 8) & 0xFF); + buffer[encapsulation_length + 10] = 0x00; + buffer[encapsulation_length + 11] = 0x00; + } + break; + + // Custom content for security tokens + case eprosima::fastdds::dds::PID_IDENTITY_TOKEN: + case eprosima::fastdds::dds::PID_PERMISSIONS_TOKEN: + { + // Content is a string + properties (0) + binary properties (0) + // Should fill the whole parameter + constexpr uint16_t token_string_length = big_parameter_plength - 4 - 4 - 4; + buffer[encapsulation_length + 4] = static_cast(token_string_length & 0xFF); + buffer[encapsulation_length + 5] = static_cast((token_string_length >> 8) & 0xFF); + } + break; + } + + // Deserialize a DATA(p) + { + CDRMessage_t msg(0); + msg.init(buffer.data(), static_cast(buffer.size())); + msg.length = msg.max_size; + + RTPSParticipantAllocationAttributes att; + att.data_limits.max_user_data = parameter_length; + ParticipantProxyData out({}); + EXPECT_NO_THROW( + if (!out.readFromCDRMessage(&msg, true, network, false)) + { + failed_for_data_p.insert(pid); + } + ); + } + + // Deserialize a DATA(w) + { + CDRMessage_t msg(0); + msg.init(buffer.data(), static_cast(buffer.size())); + msg.length = msg.max_size; + + VariableLengthDataLimits limits; + limits.max_user_data = parameter_length; + WriterProxyData out(max_unicast_locators, max_multicast_locators, limits); + EXPECT_NO_THROW( + if (!out.readFromCDRMessage(&msg, network, true)) + { + failed_for_data_w.insert(pid); + } + ); + } + + // Deserialize a DATA(r) + { + CDRMessage_t msg(0); + msg.init(buffer.data(), static_cast(buffer.size())); + msg.length = msg.max_size; + + VariableLengthDataLimits limits; + limits.max_user_data = parameter_length; + ReaderProxyData out(max_unicast_locators, max_multicast_locators, limits); + EXPECT_NO_THROW( + if (!out.readFromCDRMessage(&msg, network, true)) + { + failed_for_data_r.insert(pid); + } + ); + } + } + + // Check if any parameter ID failed + EXPECT_EQ(failed_for_data_p.size(), 0u); + EXPECT_EQ(failed_for_data_w.size(), 0u); + EXPECT_EQ(failed_for_data_r.size(), 0u); + + // Print the failed parameter IDs + if (!failed_for_data_p.empty()) + { + std::cout << "Failed for DATA(p): "; + for (uint16_t pid : failed_for_data_p) + { + std::cout << std::hex << std::setfill('0') << std::setw(4) << pid << " "; + } + std::cout << std::endl; + } + if (!failed_for_data_w.empty()) + { + std::cout << "Failed for DATA(w): "; + for (uint16_t pid : failed_for_data_w) + { + std::cout << std::hex << std::setfill('0') << std::setw(4) << pid << " "; + } + std::cout << std::endl; + } + if (!failed_for_data_r.empty()) + { + std::cout << "Failed for DATA(r): "; + for (uint16_t pid : failed_for_data_r) + { + std::cout << std::hex << std::setfill('0') << std::setw(4) << pid << " "; + } + std::cout << std::endl; + } +} + } // namespace rtps } // namespace fastrtps } // namespace eprosima