New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BalanceTimeDuration: CreateTimeDurationRecord can create too large duration values #2785
Comments
I went through the comment threads on #2727 and I guess you are referring to #2727 (comment)? Unfortunately I must have missed that reply at the time. I agree, we'll just have to make BalanceTimeDuration fallible again, unfortunately. |
Oh, ugh. It's not just a question of adding "If IsValidDuration(0, 0, 0, days, ..., nanoseconds) is false, throw a RangeError exception" to BalanceTimeDuration, because as you pointed out, the duration in the test case (which is already in test262 in test/built-ins/Temporal/Duration/prototype/round/out-of-range-when-converting-from-normalized-duration.js) actually is a valid duration according to IsValidDuration. I'm thinking of replacing step 6 in IsValidDuration with this:
That seems correct because the ℝ(𝔽(...)) values are what will be retrieved from the Duration slots if the user does any subsequent calculations with that Duration. But you probably have thought about this a lot more than I have. Do you know of any cases where replacing the above line would actually allow some cases that would currently be disallowed? Do you have any alternative suggestions? |
This test isn't testing what the assertion message previously said it was testing. The integer is allowed to be unsafe, but in this case its float64-representation is out of range. See: tc39/proposal-temporal#2785
I think that approach should work. The |
There was an edge case, spotted by Anba, where floating-point rounding at the point of conversion from normalized form to Duration storage form, in BalanceTimeDuration, can result in a Duration storage form that fails assertions. For example, when a normalized time duration is the maximum possible value { [[TotalNanoseconds]]: 9007199254740991999999999 }, and BalanceTimeDuration is called with largestUnit nanoseconds. This is already covered by test262 tests. Closes: #2785
This test isn't testing what the assertion message previously said it was testing. The integer is allowed to be unsafe, but in this case its float64-representation is out of range. See: tc39/proposal-temporal#2785
This test isn't testing what the assertion message previously said it was testing. The integer is allowed to be unsafe, but in this case its float64-representation is out of range. See: tc39/proposal-temporal#2785
… r=mgaudet BalanceTimeDuration is fallible, cf. <tc39/proposal-temporal#2785>. Depends on D204393 Differential Revision: https://phabricator.services.mozilla.com/D204394
Commit 1643cc6 only changed |
I'll address that in the next editorial PR, thanks. |
… r=mgaudet BalanceTimeDuration is fallible, cf. <tc39/proposal-temporal#2785>. Depends on D204393 Differential Revision: https://phabricator.services.mozilla.com/D204394
Commit 1643cc6 only changed IsValidDuration to correctly reject too-large duration values, but the other half was that BalanceTimeDuration needs to be able to throw when that happens. BalanceTimeDuration can throw due to floating-point rounding error if the normalized time duration could be nearby the limit and largestUnit is milliseconds, microseconds, or nanoseconds. Closes: #2785
Commit 1643cc6 only changed IsValidDuration to correctly reject too-large duration values, but the other half was that BalanceTimeDuration needs to be able to throw when that happens. BalanceTimeDuration can throw due to floating-point rounding error if the normalized time duration could be nearby the limit and largestUnit is milliseconds, microseconds, or nanoseconds. Closes: #2785
Mentioned in review for #2727.
The final
CreateTimeDurationRecord
in BalanceTimeDuration can create duration values which are larger than the maximum allowed duration.Test case:
BalanceTimeDuration is called with
norm = {[[TotalNanoseconds]]: 9007199254740991999999999}
(the largest possible duration value). The final step inBalanceTimeDuration
calls CreateTimeDurationRecord withnanoseconds = 9007199254740991999999999
, which performs:The assertion in step 1 passes, because all computations are performed using mathematical values. But
ℝ(𝔽(nanoseconds))
in step 2 performsℝ(𝔽(9007199254740991999999999)) = 9007199254740992000000000
. And9007199254740992000000000
exceeds the maximum allowed duration value.The text was updated successfully, but these errors were encountered: