You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expect.Int.it() and Expect.Natural.it() narrow a Double to Integer via Double::intValue
without first checking the value fits in int range. Double.intValue() doesn't throw for a
value outside int range — it saturates, returning Integer.MAX_VALUE/Integer.MIN_VALUE. Since
the saturated value is still a "valid" integer (and, for Natural, still >= 0), no downstream
check catches it, e.g. malloc.of 1000000000000000 silently allocates a 2147483647-byte block
instead of raising a domain error for a size nowhere near what was requested.
Added a must step before the Double::intValue narrowing in both Expect.Int and Expect.Natural that rejects any value outside [Integer.MIN_VALUE, Integer.MAX_VALUE] with a "must fit into int range" message, matching the existing style of this validation pipeline
(must be an integer, must be greater or equal to zero).
Added two tests in ExpectTest (failsInTransformingToIntegerForTooLarge, failsInTransformingToNonNegativeIntegerForTooLarge) mirroring the existing failsInTransformingTo...ForNotInteger/ForNegative tests, using 1.0e15 as the out-of-range
value from the issue's reproduction.
Ran the full Expect-related test suite locally (ExpectTest, EOmallocAllocatedExpectTest, EOmallocWritePhiExpectTest, EOiConvertersExpectTest, EObytesEOrightExpectTest, EOi64ExpectTest) — all 36 tests pass.
All benchmarks are within the acceptable range. No critical degradation detected (threshold is 100%). Please refer to the detailed report for more information.
Click to see the detailed report
Test
Base Score
PR Score
Change
% Change
Unit
Mode
benchmarks.XmirBench.xmirToEO
10803.912
10940.517
136.606
1.26%
ms/op
Average Time
⚠️ Performance loss: benchmarks.XmirBench.xmirToEO is slower by 136.606 ms/op (1.26%)
@yegor256 Thanks for the review! You've earned +7 points for this: +12 as a basis; -5 for very few (1) comments. Your running score is +1695; don't forget to check your Zerocracy account too).
@morphqdd Thanks for the contribution! You've earned +16 points. Please, keep them coming. Your running score is +640; don't forget to check your Zerocracy account too).
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
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.
Closes #5295.
Expect.Int.it()andExpect.Natural.it()narrow aDoubletoIntegerviaDouble::intValuewithout first checking the value fits in
intrange.Double.intValue()doesn't throw for avalue outside
intrange — it saturates, returningInteger.MAX_VALUE/Integer.MIN_VALUE. Sincethe saturated value is still a "valid" integer (and, for
Natural, still>= 0), no downstreamcheck catches it, e.g.
malloc.of 1000000000000000silently allocates a2147483647-byte blockinstead of raising a domain error for a size nowhere near what was requested.
Added a
muststep before theDouble::intValuenarrowing in bothExpect.IntandExpect.Naturalthat rejects any value outside[Integer.MIN_VALUE, Integer.MAX_VALUE]with a"must fit into int range"message, matching the existing style of this validation pipeline(
must be an integer,must be greater or equal to zero).Added two tests in
ExpectTest(failsInTransformingToIntegerForTooLarge,failsInTransformingToNonNegativeIntegerForTooLarge) mirroring the existingfailsInTransformingTo...ForNotInteger/ForNegativetests, using1.0e15as the out-of-rangevalue from the issue's reproduction.
Ran the full
Expect-related test suite locally (ExpectTest,EOmallocAllocatedExpectTest,EOmallocWritePhiExpectTest,EOiConvertersExpectTest,EObytesEOrightExpectTest,EOi64ExpectTest) — all 36 tests pass.