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

Incorrect ReaderProxyData object serialization code #5566

Open
1 task done
i-and opened this issue Jan 12, 2025 · 2 comments
Open
1 task done

Incorrect ReaderProxyData object serialization code #5566

i-and opened this issue Jan 12, 2025 · 2 comments
Labels

Comments

@i-and
Copy link

i-and commented Jan 12, 2025

Is there an already existing issue for this?

  • I have searched the existing issues

Expected behavior

The calculated size of the ReaderProxyData object is correct.

Current behavior

The calculated size of the ReaderProxyData object is not correct.

Steps to reproduce

See code fragment

Fast DDS version/commit

master

Platform/Architecture

Ubuntu Focal 20.04 amd64

Transport layer

UDPv4

Additional context

  1. In the ReaderProxyData::get_serialized_size() method, objects m_type_information and m_qos.type_consistency are counted twice.
  2. In the ReaderProxyData::writeToCDRMessage() method, object m_type_information is serialized when object m_type_id exists.

Proposed changes:

diff --git a/src/cpp/rtps/builtin/data/ReaderProxyData.cpp b/src/cpp/rtps/builtin/data/ReaderProxyData.cpp
index e3c2f1b6d..c3d16c9c9 100644
--- a/src/cpp/rtps/builtin/data/ReaderProxyData.cpp
+++ b/src/cpp/rtps/builtin/data/ReaderProxyData.cpp
@@ -294,17 +294,6 @@ uint32_t ReaderProxyData::get_serialized_size(
         ret_val += dds::QosPoliciesSerializer<dds::DisablePositiveACKsQosPolicy>::cdr_serialized_size(
             m_qos.m_disablePositiveACKs);
     }
-    if (m_type_information && m_type_information->assigned())
-    {
-        ret_val +=
-                dds::QosPoliciesSerializer<dds::xtypes::TypeInformationParameter>::cdr_serialized_size(
-            *m_type_information);
-    }
-    if (m_qos.type_consistency.send_always() || m_qos.type_consistency.hasChanged)
-    {
-        ret_val += dds::QosPoliciesSerializer<dds::TypeConsistencyEnforcementQosPolicy>::cdr_serialized_size(
-            m_qos.type_consistency);
-    }
     if ((m_qos.data_sharing.send_always() || m_qos.data_sharing.hasChanged) &&
             m_qos.data_sharing.kind() != fastdds::dds::OFF)
     {
@@ -579,14 +568,6 @@ bool ReaderProxyData::writeToCDRMessage(
         }
     }
 
-    if (m_type_id && m_type_id->m_type_identifier._d() != fastdds::dds::xtypes::TK_NONE)
-    {
-        if (!dds::QosPoliciesSerializer<dds::xtypes::TypeInformationParameter>::add_to_cdr_message(
-                    *m_type_information, msg))
-        {
-            return false;
-        }
-    }
     if (m_properties.size() > 0)
     {
         if (!dds::ParameterSerializer<dds::ParameterPropertyList_t>::add_to_cdr_message(m_properties, msg))

XML configuration file

No response

Relevant log output

No response

Network traffic capture

No response

@i-and i-and added the triage Issue pending classification label Jan 12, 2025
@MiguelCompany
Copy link
Member

@i-and Would be nice if you open a PR with the proposed changes and a regression test

@MiguelCompany MiguelCompany added to-do and removed triage Issue pending classification labels Jan 13, 2025
@i-and
Copy link
Author

i-and commented Jan 13, 2025

These suggestions appeared based on the results of code analysis of the ReaderProxyData and they are not related to any observed failures. But the following was noticed:

  1. In the ReaderProxyData::get_serialized_size() method, two code fragments are duplicated:
    if (m_type_information && m_type_information->assigned())
    {
    ret_val +=
    dds::QosPoliciesSerializer<dds::xtypes::TypeInformationParameter>::cdr_serialized_size(
    *m_type_information);
    }

    if (m_type_information && m_type_information->assigned())
    {
    ret_val +=
    dds::QosPoliciesSerializer<dds::xtypes::TypeInformationParameter>::cdr_serialized_size(
    *m_type_information);
    }

    and
    if (m_qos.type_consistency.send_always() || m_qos.type_consistency.hasChanged)
    {
    ret_val += dds::QosPoliciesSerializer<dds::TypeConsistencyEnforcementQosPolicy>::cdr_serialized_size(
    m_qos.type_consistency);
    }

    if (m_qos.type_consistency.send_always() || m_qos.type_consistency.hasChanged)
    {
    ret_val += dds::QosPoliciesSerializer<dds::TypeConsistencyEnforcementQosPolicy>::cdr_serialized_size(
    m_qos.type_consistency);
    }

    This leads to excessive memory requirements because the sizes of objects m_type_information and m_qos.type_consistency are taken into account twice. Therefore, it was proposed to remove duplicate sections of the code.
  2. In the ReaderProxyData::writeToCDRMessage() one object is checked (m_type_id) and another (m_type_information) is used, which can lead to access to a non-existent object m_type_information:
    if (m_type_id && m_type_id->m_type_identifier._d() != fastdds::dds::xtypes::TK_NONE)
    {
    if (!dds::QosPoliciesSerializer<dds::xtypes::TypeInformationParameter>::add_to_cdr_message(
    *m_type_information, msg))
    {
    return false;
    }
    }

    I suggest deleting this code because the object m_type_information is written correctly in this method below:
    if (m_type_information && m_type_information->assigned())
    {
    if (!dds::QosPoliciesSerializer<dds::xtypes::TypeInformationParameter>::add_to_cdr_message(
    *m_type_information, msg))
    {
    return false;
    }
    }

    I'm not sure if a separate regression test is needed for these cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants