From 915c09dbda8fd1da8c4e3974ba584fba9d996563 Mon Sep 17 00:00:00 2001 From: Joe Betz Date: Tue, 22 Aug 2023 10:02:10 -0700 Subject: [PATCH] check for overflow Co-authored-by: Jordan Liggitt Kubernetes-commit: 175bbaa8894a683cb7ba09f1e36160bc187840e4 --- pkg/cel/library/cost.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/cel/library/cost.go b/pkg/cel/library/cost.go index 147b54cb8..3d1b3fbb2 100644 --- a/pkg/cel/library/cost.go +++ b/pkg/cel/library/cost.go @@ -131,8 +131,10 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch // find the longest replacement: if toReplaceSz.Min == 0 { // if the string being replaced is empty, replace surrounds all characters in the input string with the replacement. - if replaceCount.Max < math.MaxUint64 { + if sz.Max < math.MaxUint64 { replaceCount.Max = sz.Max + 1 + } else { + replaceCount.Max = sz.Max } // Include the length of the longest possible original string length. retainedSz.Max = sz.Max @@ -149,8 +151,10 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch // find the shortest replacement: if toReplaceSz.Max == 0 { // if the string being replaced is empty, replace surrounds all characters in the input string with the replacement. - if replaceCount.Min < math.MaxUint64 { + if sz.Min < math.MaxUint64 { replaceCount.Min = sz.Min + 1 + } else { + replaceCount.Min = sz.Min } // Include the length of the shortest possible original string length. retainedSz.Min = sz.Min