Handle large numbers in filter values - #253
Open
peterbroadhurst wants to merge 2 commits into
Open
peterbroadhurst wants to merge 2 commits into
peterbroadhurst wants to merge 2 commits into
Conversation
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
peterbroadhurst
added this pull request to stack #255
October 1, 2026 18:58
EnriqueL8
approved these changes
Oct 2, 2026
EnriqueL8
left a comment
Contributor
There was a problem hiding this comment.
Thanks @peterbroadhurst , looks good - we should definitely fix also query builder path
common/pkg/ffapi/restfilter_json_builder.go
Line 127 in 0dd2e22
| return true | ||
| } | ||
| exp, err := strconv.Atoi(s[i+1:]) | ||
| limit := maxFilterNumberLength + maxFilterNumberDigits |
Contributor
There was a problem hiding this comment.
you could move this limit to a const above
| `0.0009765625`: "0.0009765625", // 1/1024 - more places than denominator digits | ||
| `9007199254740993e0`: "9007199254740993", | ||
| `123456789012345678901.5`: "123456789012345678901.5", | ||
| `1e30`: "1000000000000000000000000000000", |
Contributor
There was a problem hiding this comment.
nit: worth adding an uppercase E test
| // boundedLiteral reports whether s, a valid JSON number, is short enough and has a small enough | ||
| // exponent that the value might fit in maxFilterNumberBits. | ||
| // Check before parsing to big.Rat (per gosec G113) | ||
| func boundedLiteral(s string) bool { |
Contributor
There was a problem hiding this comment.
note that is safe after json.Number conversion, I believe a hex number would still pass this such as 0x1p999999999 and result in gosec 113. json.Number explicitly doesn't allow that hex format
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.
If you tried to pass a large JSON number into the JSONQuery structure, it would end up being incorrectly parsed into
float64in the utility during JSON unmarshal, and there's no way for a user of this utility package to avoid that rounding issue.This PR uses
json.Number+big.Ratparsing instead to handle large numbers, while still producing the same plain formatting in the string returned (removing1.234e10style syntax).