Skip to content

Commit 915c09d

Browse files
jpbetzk8s-publishing-bot
authored andcommitted
check for overflow
Co-authored-by: Jordan Liggitt <[email protected]> Kubernetes-commit: 175bbaa8894a683cb7ba09f1e36160bc187840e4
1 parent 6394fb8 commit 915c09d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/cel/library/cost.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch
131131
// find the longest replacement:
132132
if toReplaceSz.Min == 0 {
133133
// if the string being replaced is empty, replace surrounds all characters in the input string with the replacement.
134-
if replaceCount.Max < math.MaxUint64 {
134+
if sz.Max < math.MaxUint64 {
135135
replaceCount.Max = sz.Max + 1
136+
} else {
137+
replaceCount.Max = sz.Max
136138
}
137139
// Include the length of the longest possible original string length.
138140
retainedSz.Max = sz.Max
@@ -149,8 +151,10 @@ func (l *CostEstimator) EstimateCallCost(function, overloadId string, target *ch
149151
// find the shortest replacement:
150152
if toReplaceSz.Max == 0 {
151153
// if the string being replaced is empty, replace surrounds all characters in the input string with the replacement.
152-
if replaceCount.Min < math.MaxUint64 {
154+
if sz.Min < math.MaxUint64 {
153155
replaceCount.Min = sz.Min + 1
156+
} else {
157+
replaceCount.Min = sz.Min
154158
}
155159
// Include the length of the shortest possible original string length.
156160
retainedSz.Min = sz.Min

0 commit comments

Comments
 (0)