Skip to content

Commit a685dd5

Browse files
committed
Introduce validation to the ColumnArray constructor
The ColumnArray constructor would just accept incompatible value- and offset-arrays and the client would then happily send them, causing issues in the ClickHouse server. This introduces validation of the arrays.
1 parent fbd7945 commit a685dd5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

clickhouse/columns/array.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ ColumnArray::ColumnArray(ColumnRef data, std::shared_ptr<ColumnUInt64> offsets)
1515
, data_(data)
1616
, offsets_(offsets)
1717
{
18+
const auto rows = offsets_->Size();
19+
const auto expected_values = rows > 0 ? offsets_->At(rows - 1) : 0;
20+
std::uint64_t prev = 0;
21+
// Ensure the offset array is internally consistent
22+
for (const auto& o : offsets_->GetWritableData()) {
23+
if (o < prev) {
24+
throw ValidationError("offsets must be monotonically increasing");
25+
}
26+
prev = o;
27+
}
28+
if (data_->Size() != expected_values) {
29+
throw ValidationError("Mismatch between data and offsets: Expected " + std::to_string(expected_values) +
30+
" values in data, but got " + std::to_string(data_->Size()));
31+
}
1832
}
1933

2034
ColumnArray::ColumnArray(ColumnArray&& other)

0 commit comments

Comments
 (0)