[CH] ReadFromGlutenStorageKafka stores column_names as a dangling const Names& reference
- Dominant language
- Scala
- Stars
- 1.6k
- Forks
- 657
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 80
Description
### Description
`ReadFromGlutenStorageKafka` stores its `column_names` as a **reference** member:
```cpp
// 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
// cpp-ch/local-engine/Parser/RelParsers/StreamKafkaRelParser.cpp:102-107
Names names = header->getNames();
auto source = std::make_unique(
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.
Contributor guide
Research direction
Read cpp-ch/local-engine/Storages/Kafka/ReadFromGlutenStorageKafka.h and .cpp, then inspect the construction in cpp-ch/local-engine/Parser/RelParsers/StreamKafkaRelParser.cpp. Remove the unused column_names reference and its constructor parameter, or make the member owning; confirm the Kafka source and parser still build without a dangling reference.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, kafka
- Domain
- stream-processing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100