From c795b9c32f9c6eba1d0fd36fc4681691eab796a6 Mon Sep 17 00:00:00 2001 From: Antonio Andelic Date: Thu, 7 Sep 2023 07:54:06 +0000 Subject: [PATCH] Check for overflow before addition in anova function --- src/AggregateFunctions/Moments.h | 4 ++++ .../0_stateless/02874_analysis_of_variance_overflow.reference | 0 .../0_stateless/02874_analysis_of_variance_overflow.sql | 1 + 3 files changed, 5 insertions(+) create mode 100644 tests/queries/0_stateless/02874_analysis_of_variance_overflow.reference create mode 100644 tests/queries/0_stateless/02874_analysis_of_variance_overflow.sql diff --git a/src/AggregateFunctions/Moments.h b/src/AggregateFunctions/Moments.h index a34f960794c..099bc11d0c8 100644 --- a/src/AggregateFunctions/Moments.h +++ b/src/AggregateFunctions/Moments.h @@ -459,6 +459,10 @@ struct AnalysisOfVarianceMoments void add(T value, size_t group) { + if (group == std::numeric_limits::max()) + throw Exception(ErrorCodes::BAD_ARGUMENTS, "Too many groups for analysis of variance (should be no more than {}, got {})", + MAX_GROUPS_NUMBER, group); + resizeIfNeeded(group + 1); xs1[group] += value; xs2[group] += value * value; diff --git a/tests/queries/0_stateless/02874_analysis_of_variance_overflow.reference b/tests/queries/0_stateless/02874_analysis_of_variance_overflow.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/queries/0_stateless/02874_analysis_of_variance_overflow.sql b/tests/queries/0_stateless/02874_analysis_of_variance_overflow.sql new file mode 100644 index 00000000000..67fb4d28acb --- /dev/null +++ b/tests/queries/0_stateless/02874_analysis_of_variance_overflow.sql @@ -0,0 +1 @@ +SELECT analysisOfVariance(1, 18446744073709551615); -- { serverError BAD_ARGUMENTS }