Skip to content

Commit

Permalink
Backport #54385 to 23.6: Check for overflow before addition in `analy…
Browse files Browse the repository at this point in the history
…sisOfVariance` function
  • Loading branch information
robot-clickhouse committed Sep 7, 2023
1 parent 2a4ee7d commit 2ba177f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/AggregateFunctions/Moments.h
Expand Up @@ -459,6 +459,10 @@ struct AnalysisOfVarianceMoments

void add(T value, size_t group)
{
if (group == std::numeric_limits<size_t>::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;
Expand Down
Empty file.
@@ -0,0 +1 @@
SELECT analysisOfVariance(1, 18446744073709551615); -- { serverError BAD_ARGUMENTS }

0 comments on commit 2ba177f

Please sign in to comment.