Skip to content

Commit d23378d

Browse files
committed
[C++] Fix null pointer dereference in SimpleTable constructor
The SimpleTable constructors dereference columns_[0] and columns[0] without checking for null when num_rows < 0. This causes a segfault if a user passes a vector containing null pointers, as the null check in ValidateMeta() runs after construction. Fixed by adding null checks before dereferencing the first column.
1 parent 222fac7 commit d23378d

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

cpp/src/arrow/table.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SimpleTable : public Table {
6363
: columns_(std::move(columns)) {
6464
schema_ = std::move(schema);
6565
if (num_rows < 0) {
66-
if (columns_.size() == 0) {
66+
if (columns_.size() == 0 || !columns_[0]) {
6767
num_rows_ = 0;
6868
} else {
6969
num_rows_ = columns_[0]->length();
@@ -77,7 +77,7 @@ class SimpleTable : public Table {
7777
const std::vector<std::shared_ptr<Array>>& columns, int64_t num_rows = -1) {
7878
schema_ = std::move(schema);
7979
if (num_rows < 0) {
80-
if (columns.size() == 0) {
80+
if (columns.size() == 0 || !columns[0]) {
8181
num_rows_ = 0;
8282
} else {
8383
num_rows_ = columns[0]->length();

0 commit comments

Comments
 (0)