Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

batizdaniel
Copy link
Contributor

This patch fixes #4704

JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz daniel.batiz@h-lab.eu

Copy link
Member

@dbatyai dbatyai left a 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.

@ossy-szeged
Copy link
Contributor

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.

@dbatyai
Copy link
Member

dbatyai commented Jan 18, 2022

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.

@ossy-szeged
Copy link
Contributor

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):
DayFromYear(y) = 𝔽(365 × (ℝ(y) - 1970) + floor((ℝ(y) - 1969) / 4) - floor((ℝ(y) - 1901) / 100) + floor((ℝ(y) - 1601) / 400))

@batizdaniel batizdaniel force-pushed the issue_04 branch 2 times, most recently from 3f690a8 to e0cb639 Compare January 21, 2022 13:45
This patch fixes jerryscript-project#4704

JerryScript-DCO-1.0-Signed-off-by: Daniel Batiz daniel.batiz@h-lab.eu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants