fix: clamp ceilToInt64 to prevent float-to-int truncation overflow#7819
Open
Fedosin wants to merge 1 commit into
Open
fix: clamp ceilToInt64 to prevent float-to-int truncation overflow#7819Fedosin wants to merge 1 commit into
Fedosin wants to merge 1 commit into
Conversation
|
Thank you for your contribution! 🙏 Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected. While you are waiting, make sure to:
Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient. Learn more about our contribution guide. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
ceilToInt64 silently wraps to math.MinInt64 when the input float64 is >= 2^63 due to IEEE 754 CVTTSD2SI returning "integer indefinite" for out-of-range values. This can cause unintended scale-down to zero for ScaledJobs when a scaler returns an extremely large metric value. Add overflow guards that clamp to math.MaxInt64 / math.MinInt64 before the float-to-int conversion, and add regression tests covering boundary values and infinities. Fixes kedacore#7796 Signed-off-by: Mikhail Fedosin <mfedosin@redhat.com>
c820fd2 to
187c45a
Compare
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.
ceilToInt64inpkg/scaling/scaledjob/metrics.gosilently wraps tomath.MinInt64instead of returningmath.MaxInt64when the inputfloat64is >= 2^63 (≈ 9.22 × 10^18). The conversionint64(math.Ceil(x))compiles to aCVTTSD2SIinstruction on x86-64; IEEE 754 specifies that this instruction returns the "integer indefinite" value (0x8000000000000000=math.MinInt64) for any out-of-range input — there is no runtime panic and no error, just a silently wrong result.This adds overflow guards that clamp to
math.MaxInt64/math.MinInt64before the float-to-int conversion, along with regression tests covering normal values, boundary values (2^63 exactly), large positive/negative values, and ±Inf.Checklist
make generate-scalers-schemahas been run to update any outdated generated filesFixes #7796