Fix possible out of bounds error while reading LowCardinality(Nullable) in Arrow format

This commit is contained in:
avogar 2023-02-10 12:57:47 +00:00
parent 8bdb1c3453
commit deda940d87
3 changed files with 18 additions and 1 deletions

View File

@ -384,9 +384,10 @@ static ColumnWithTypeAndName readColumnWithIndexesDataImpl(std::shared_ptr<arrow
const auto * data = reinterpret_cast<const NumericType *>(buffer->data());
/// Check that indexes are correct (protection against corrupted files)
/// Note that on null values index can be arbitrary value.
for (int64_t i = 0; i != chunk->length(); ++i)
{
if (data[i] < 0 || data[i] >= dict_size)
if (!chunk->IsNull(i) && (data[i] < 0 || data[i] >= dict_size))
throw Exception(ErrorCodes::INCORRECT_DATA,
"Index {} in Dictionary column is out of bounds, dictionary size is {}",
Int64(data[i]), UInt64(dict_size));

View File

@ -0,0 +1,2 @@
0
\N

View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# Tags: no-fasttest
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh
. "$CUR_DIR"/../shell_config.sh
$CLICKHOUSE_CLIENT -q "drop table if exists test"
$CLICKHOUSE_CLIENT -q "create table test (z LowCardinality(Nullable(String))) engine=Memory";
$CLICKHOUSE_CLIENT -q "select CAST(number % 2 ? NULL : toString(number), 'LowCardinality(Nullable(String))') as z from numbers(2) format Arrow settings output_format_arrow_low_cardinality_as_dictionary=1" | $CLICKHOUSE_CLIENT -q "insert into test format Arrow"
$CLICKHOUSE_CLIENT -q "select * from test"
$CLICKHOUSE_CLIENT -q "drop table test"