fix: provide ResultSize for string.format() cost estimate#1322
Open
Dhakshin2007 wants to merge 1 commit into
Open
fix: provide ResultSize for string.format() cost estimate#1322Dhakshin2007 wants to merge 1 commit into
Dhakshin2007 wants to merge 1 commit into
Conversation
Prior to this fix, the ExtFormatString cost case returned no ResultSize, with the comment "ResultSize not calculated because we can't bound the max size." Since PR cel-expr#1292 introduced StringsMaxPrecision (defaulting to 100 for v5+), the output size of string.format() is now bounded: each format clause expands an argument by at most maxPrecision + small constant characters. The output is therefore bounded by the format string size plus the sum of argument string sizes. This change computes ResultSize = targetSize + argsSize, enabling downstream cost-tracking expressions (e.g. format output passed to contains(), size(), or string concatenation) to have accurate cost estimates, which is important for enforcing compute limits in security-sensitive CEL evaluation contexts.
Collaborator
|
/gcbrun |
| case overloads.ExtFormatString: | ||
| if target != nil { | ||
| // ResultSize not calculated because we can't bound the max size. | ||
| // ResultSize is bounded: since precision is capped by StringsMaxPrecision, // the output cannot exceed the format string size plus the sum of // argument string sizes (each numeric arg expands by at most // maxPrecision + fixed overhead characters). |
Collaborator
There was a problem hiding this comment.
Unfortunately, I can't change these lines and instead would need to move the existing cost caculations into the ext/strings.go implementation and associate it with v0-v4 of the library, and the update written here with the v5+ versions of the library
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.
Prior to this fix, the ExtFormatString cost case returned no ResultSize, with the comment "ResultSize not calculated because we can't bound the max size."
Since PR #1292 introduced StringsMaxPrecision (defaulting to 100 for v5+), the output size of string.format() is now bounded: each format clause expands an argument by at most maxPrecision + small constant characters. The output is therefore bounded by the format string size plus the sum of argument string sizes.
This change computes ResultSize = targetSize + argsSize, enabling downstream cost-tracking expressions (e.g. format output passed to contains(), size(), or string concatenation) to have accurate cost estimates, which is important for enforcing compute limits in security-sensitive CEL evaluation contexts.
Pull Requests Guidelines
See CONTRIBUTING.md for more details about when to create
a GitHub Pull Request and when other kinds of contributions or
consultation might be more desirable.
When creating a new pull request, please fork the repo and work within a
development branch.
Commit Messages
Reviews
Merging
they have write access. Otherwise, the change will be merged by a maintainer.
closes #<issue-num>: descriptionin the merge message,if applicable.