Skip to content

[C++] MakeExecBatch would dereference null pointer when the input Datum is constructed from a Table #48062

@Lancern

Description

@Lancern

Describe the bug, including details regarding any error messages, version, and platform.

In function arrow::compute::MakeExecBatch it checks for the input Datum's type id:

if (partial.type()->id() == Type::STRUCT) {

Datum::type() can return null pointers. This will happen when the Datum is constructed from a record batch or a table:

const std::shared_ptr<DataType>& Datum::type() const {
if (this->kind() == Datum::ARRAY) {
return std::get<std::shared_ptr<ArrayData>>(this->value)->type;
}
if (this->kind() == Datum::CHUNKED_ARRAY) {
return std::get<std::shared_ptr<ChunkedArray>>(this->value)->type();
}
if (this->kind() == Datum::SCALAR) {
return std::get<std::shared_ptr<Scalar>>(this->value)->type;
}
static std::shared_ptr<DataType> no_type;
return no_type;
}

However, the MakeExecBatch function does not check whether the datum is a table before Datum::type() is used. This leads to a null pointer dereference when the id() function is called.

I suggest we additionally check that Datum::type() does not return a null pointer before calling id() on it.

Component(s)

C++

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions