Skip to content

Commit 214fd3c

Browse files
Merge pull request #69 from ClickHouse/ncb/arrow-crash-fixes
pull in some fixes for possible crash in TableBatchReader
2 parents ae9f3d6 + b12b19a commit 214fd3c

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

cpp/src/arrow/table.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ TableBatchReader::TableBatchReader(const Table& table)
619619
for (int i = 0; i < table.num_columns(); ++i) {
620620
column_data_[i] = table.column(i).get();
621621
}
622+
DCHECK(table_.Validate().ok());
622623
}
623624

624625
TableBatchReader::TableBatchReader(std::shared_ptr<Table> table)
@@ -632,6 +633,7 @@ TableBatchReader::TableBatchReader(std::shared_ptr<Table> table)
632633
for (int i = 0; i < owned_table_->num_columns(); ++i) {
633634
column_data_[i] = owned_table_->column(i).get();
634635
}
636+
DCHECK(table_.Validate().ok());
635637
}
636638

637639
std::shared_ptr<Schema> TableBatchReader::schema() const { return table_.schema(); }

cpp/src/arrow/table.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ class ARROW_EXPORT Table {
241241
///
242242
/// The conversion is zero-copy: each record batch is a view over a slice
243243
/// of the table's columns.
244+
///
245+
/// The table is expected to be valid prior to using it with the batch reader.
244246
class ARROW_EXPORT TableBatchReader : public RecordBatchReader {
245247
public:
246248
/// \brief Construct a TableBatchReader for the given table

cpp/src/parquet/arrow/reader.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,16 @@ Status FileReaderImpl::GetRecordBatchReader(const std::vector<int>& row_groups,
10431043
}
10441044
}
10451045

1046+
// Check all columns has same row-size
1047+
if (!columns.empty()) {
1048+
int64_t row_size = columns[0]->length();
1049+
for (size_t i = 1; i < columns.size(); ++i) {
1050+
if (columns[i]->length() != row_size) {
1051+
return ::arrow::Status::Invalid("columns do not have the same size");
1052+
}
1053+
}
1054+
}
1055+
10461056
auto table = ::arrow::Table::Make(batch_schema, std::move(columns));
10471057
auto table_reader = std::make_shared<::arrow::TableBatchReader>(*table);
10481058

0 commit comments

Comments
 (0)