ext/strings: add cost estimators for string extension functions#1297
Open
mohammadmseet-hue wants to merge 1 commit intogoogle:masterfrom
Open
ext/strings: add cost estimators for string extension functions#1297mohammadmseet-hue wants to merge 1 commit intogoogle:masterfrom
mohammadmseet-hue wants to merge 1 commit intogoogle:masterfrom
Conversation
The ext.Strings library registers 13+ string manipulation functions
(split, join, replace, indexOf, etc.) without any compile-time cost
estimators or runtime cost trackers. All string extension functions
fall through to a default O(1) cost, regardless of actual input size.
This means CEL cost limits are ineffective for string extension
operations: a split("").join("XXX") chain can amplify a 10KB input
into 63MB of memory allocation while the cost tracker reports a
total cost of 9.
Add CostEstimatorOptions to CompileOptions() and CostTrackerOptions
to ProgramOptions() for all string extension overloads, following
the same pattern used by ext/regex.go and ext/lists.go.
The strings.quote and string.format overloads are excluded as they
are already tracked by the default runtime cost calculator via
overloads.ExtQuoteString and overloads.ExtFormatString.
Fixes cost tracking for: charAt, indexOf, lastIndexOf, lowerAscii,
upperAscii, replace, split, join, substring, trim, and reverse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
ext.Stringslibrary registers 13+ string manipulation functions without any compile-time cost estimators or runtime cost trackers. All string extension functions fall through to a default O(1) cost in both the static cost checker (checker/cost.go) and runtime cost tracker (interpreter/runtimecost.go), regardless of actual input size or computational complexity.Every other CEL-GO extension library registers cost estimators:
ext/lists.gohas 28,ext/regex.gohas 15,ext/sets.gohas 12.ext/strings.gohas zero.This means
cel.CostLimit()is ineffective for expressions using string extension functions. For example, chainingsplit("")andjoin("XXX")calls can amplify a small input into significant memory allocation while the cost tracker reports a trivially low cost.Changes
checker.OverloadCostEstimateentries inCompileOptions()for all string extension overloadsinterpreter.OverloadCostTrackerentries inProgramOptions()for all string extension overloadsext/regex.goandext/lists.go:strings.quoteandstring.formatare excluded as they are already tracked by the default runtime cost calculator viaoverloads.ExtQuoteStringandoverloads.ExtFormatStringAffected overloads
string_char_at_intstring_index_of_stringstring_index_of_string_intstring_last_index_of_stringstring_last_index_of_string_intstring_lower_asciistring_upper_asciistring_replace_string_stringstring_replace_string_string_intstring_split_stringstring_split_string_intstring_substring_intstring_substring_int_intstring_trimstring_reverselist_joinlist_join_stringTest plan
go test ./ext/...andgo test ./...)strings.quotetests are unaffected since quote/format are handled by the default runtime cost calculator