Skip to content

[CH] ReadFromGlutenStorageKafka stores column_names as a dangling const Names& reference #12843

Description

@nielspardon

Description

ReadFromGlutenStorageKafka stores its column_names as a reference member:

// cpp-ch/local-engine/Storages/Kafka/ReadFromGlutenStorageKafka.h:52
const Names & column_names;

initialized from the constructor's const Names & column_names_ parameter (ReadFromGlutenStorageKafka.cpp:53). The sole construction site binds it to a local that goes out of scope before the step runs:

// cpp-ch/local-engine/Parser/RelParsers/StreamKafkaRelParser.cpp:102-107
Names names = header->getNames();
auto source = std::make_unique<ReadFromGlutenStorageKafka>(
    names, header, getContext(), topics, partition, start_offset, end_offset, poll_timeout_ms, group_id, brokers);

steps.emplace_back(source.get());
query_plan->addStep(std::move(source));   // the step outlives `names`

names is destroyed when parse() returns, but the step (and its column_names reference) lives on in the query plan and runs later in initializePipeline. The reference dangles.

Impact

Latent today: column_names is never actually dereferenced — it is stored in the constructor but read nowhere (makePipe/initializePipeline/createKafkaSettings don't touch it; the Kafka source derives its schema from output_header instead). So it is a harmless-but-real dangling reference and a footgun: any future read of column_names would touch freed memory.

Fix

Either make it an owning value member — Names column_names; (drop the &) so it copies at construction — or remove the unused member entirely (and drop the now-unused column_names_ constructor parameter). Given it has no readers, removing it is the cleaner option.

Notes

Pre-existing; not introduced by the Substrait-0.98 rebase (#12597) — surfaced while reviewing this file for the Kafka ExtensionTable remodel (#12841). By contrast the sibling topics member is stored by value (Names topics;), so only column_names is affected.

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