Skip to content

Commit

Permalink
Merge pull request #54416 from ClickHouse/backport/23.7/54385
Browse files Browse the repository at this point in the history
Backport #54385 to 23.7: Check for overflow before addition in `analysisOfVariance` function
  • Loading branch information
alexey-milovidov committed Sep 7, 2023
2 parents c7b9809 + 390b6e3 commit f0b2ef9
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
Original file line number Diff line number Diff line change
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SELECT analysisOfVariance(1, 18446744073709551615); -- { serverError BAD_ARGUMENTS }

0 comments on commit f0b2ef9

Please sign in to comment.