From 01722c709959cd4ee5f94a760afb0268e0b50eb5 Mon Sep 17 00:00:00 2001 From: yariks5s Date: Wed, 20 Sep 2023 15:19:35 +0000 Subject: [PATCH] fixed uninitialized memory --- .../AggregateFunctionGroupArraySorted.h | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/AggregateFunctions/AggregateFunctionGroupArraySorted.h b/src/AggregateFunctions/AggregateFunctionGroupArraySorted.h index 5066dcf3d93..0c9d38a8a6b 100644 --- a/src/AggregateFunctions/AggregateFunctionGroupArraySorted.h +++ b/src/AggregateFunctions/AggregateFunctionGroupArraySorted.h @@ -65,8 +65,7 @@ public: void add(AggregateDataPtr __restrict place, const IColumn ** columns, size_t row_num, Arena * arena) const override { - const auto & row_values = assert_cast &>(*columns[0]).getData(); - const auto & row_value = row_values[row_num]; + const auto & row_value = assert_cast &>(*columns[0]).getData()[row_num]; auto & cur_elems = this->data(place); cur_elems.value.push_back(row_value, arena); @@ -90,8 +89,10 @@ public: if (rhs_elems.value.size()) cur_elems.value.insertByOffsets(rhs_elems.value, 0, rhs_elems.value.size(), arena); + if (cur_elems.value.size() < max_elems) + throw Exception(ErrorCodes::INCORRECT_DATA, "The max size of result array is bigger than the actual array size"); - std::sort(cur_elems.value.begin(), cur_elems.value.end()); + RadixSort>::executeLSD(cur_elems.value.data(), cur_elems.value.size()); if (limit_num_elems) cur_elems.value.resize(max_elems, arena); } @@ -136,17 +137,21 @@ public: } } - void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena * a) const override + static void checkArraySize(size_t elems, size_t max_elems) + { + if (unlikely(elems > max_elems)) + throw Exception(ErrorCodes::TOO_LARGE_ARRAY_SIZE, + "Too large array size {} (maximum: {})", elems, max_elems); + } + + void insertResultInto(AggregateDataPtr __restrict place, IColumn & to, Arena * arena) const override { auto& value = this->data(place).value; - + if (value.size() < max_elems) + throw Exception(ErrorCodes::INCORRECT_DATA, "The max size of result array is bigger than the actual array size"); RadixSort>::executeLSD(value.data(), value.size()); if (limit_num_elems) - { - if (value.size() < max_elems) - throw Exception(ErrorCodes::INCORRECT_DATA, "The max size of result array is bigger than the actual array size"); - value.resize(max_elems, a); - } + value.resize(max_elems, arena); size_t size = value.size(); ColumnArray & arr_to = assert_cast(to); @@ -247,7 +252,11 @@ public: std::sort(cur_elems.value.begin(), cur_elems.value.end()); if (limit_num_elems) + { + if (cur_elems.value.size() < max_elems) + throw Exception(ErrorCodes::INCORRECT_DATA, "The max size of result array is bigger than the actual array size"); cur_elems.value.resize(max_elems, arena); + } } void serialize(ConstAggregateDataPtr __restrict place, WriteBuffer & buf, std::optional /* version */) const override @@ -294,8 +303,8 @@ public: { auto & column_array = assert_cast(to); auto & value = data(place).value; - std::sort(value.begin(), value.end()); + std::sort(value.begin(), value.end()); if (limit_num_elems) { if (value.size() < max_elems)