Skip to content

crash with variable-size keyed samples #577

Description

@justme151

I have a problem with a keyed type that has variable serialized key size.
register_instance can crash after a short key is seen first and a longer key is registered later. I managed to create a minimal repro that demonstrates the issue.

  • CycloneDDS-CXX 11.0.1
  • OS: Debian

IDL

module repro {
  @final
  struct KeyedSample {
    @key string<255> id;
    int32 value;
  };
};

Minimal C++ program

#include <dds/dds.hpp>
#include <iostream>
#include <string>

#include "repro.hpp"

static repro::KeyedSample makeSample(const std::string& key, int32_t v) {
    repro::KeyedSample s;
    s.id(key);
    s.value(v);
    return s;
}

int main() {
    dds::domain::DomainParticipant participant(0);
    dds::topic::Topic<repro::KeyedSample> topic(participant, "myTopic");
    dds::pub::Publisher publisher(participant);
    dds::pub::DataWriter<repro::KeyedSample> writer(publisher, topic);

    const std::string shortKey = "short";
    const std::string longKey19 = "longkeyabcdefghijkl";  // 19 chars
    const std::string longKey20 = "longkeyabcdefghijklm"; // 20 chars

    writer.register_instance(makeSample(shortKey, 1));
    std::cout << "1. Works" << std::endl;
    writer.register_instance(makeSample(longKey19, 2));
    std::cout << "2. Works" << std::endl;
    writer.register_instance(makeSample(longKey20, 3)); // --> This call segfaults
    std::cout << "Won't print" << std::endl;
    return 0;
}

Steps to reproduce

  1. Generate type support from the IDL with idlc.
  2. Build the repro program against CycloneDDS-CXX.
  3. Run the program.

Result

Can someone confirm that this program crashes with segmentation fault during register_instance after key length crosses boundary in this sequence?

Output:

1. Works
2. Works
Segmentation fault (core dumped)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions