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
Fix runtime error Date object #4914
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really fix the issue, new Date(-20000000, 0)
will trigger the same behavior on the other branch.
On top of that, even though it no longer triggers an undefined behavior, the value can still overflow, for example new Date(200000000, 0)
(one extra zero), which actually results in a valid date (incorrectly).
I think the best approach would be to clamp the input year so that it's not abnormally large. The valid year range is [-271821, 275760], so clamping to a slightly larger range than that should be enough, making sure that invalid year values remain invalid.
It's not as easy. We can't clamp the input year, because there is no restriction for the arguments of the Date constructor, only the output Date object should be in the allowed interval. for example new Date(-271822, 16) is valid Date, but new Date(-271822, 15) is invalid. |
That's why I said clamping it to a slightly larger range. That will filter out abnormally large input values, that should be invalid regardless, then the rest will be handled by the conversion logic correctly without overflowing. |
https://262.ecma-international.org/12.0/#eqn-DaysFromYear The latest spec clarifies that we should handle year as mathematical value (Arbitrary real numbers, used as the default numeric type) and the result should be Number (double): |
3f690a8
to
e0cb639
Compare
This patch fixes jerryscript-project#4704 JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz daniel.batiz@h-lab.eu
This patch fixes #4704
JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz daniel.batiz@h-lab.eu