WebKit Bugzilla
Attachment 341111 Details for
Bug 185868
: Date.parse() doesn't properly handle input outside of ES Spec limits
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
185868.patch (text/plain), 7.29 KB, created by
Michael Saboff
on 2018-05-23 12:00:17 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Michael Saboff
Created:
2018-05-23 12:00:17 PDT
Size:
7.29 KB
patch
obsolete
>Index: JSTests/ChangeLog >=================================================================== >--- JSTests/ChangeLog (revision 232120) >+++ JSTests/ChangeLog (working copy) >@@ -1,3 +1,17 @@ >+2018-05-23 Michael Saboff <msaboff@apple.com> >+ >+ Date.parse() doesn't properly handle input outside of ES Spec limits >+ https://bugs.webkit.org/show_bug.cgi?id=185868 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ New test. >+ >+ * stress/date-parse-ranges.js: Added. >+ (shouldBe): >+ (throw.new.Error): >+ (shouldBeNaN): >+ > 2018-05-23 Rick Waldron <waldron.rick@gmail.com> > > Conversion misspelled "Convertion" in error message string >Index: JSTests/stress/date-parse-ranges.js >=================================================================== >--- JSTests/stress/date-parse-ranges.js (nonexistent) >+++ JSTests/stress/date-parse-ranges.js (working copy) >@@ -0,0 +1,145 @@ >+// This test checks that dates follow the range described in ecma262/#sec-date-time-string-format >+ >+function shouldBe(actual, expected) >+{ >+ if (actual !== expected) >+ throw new Error(`bad value: ${actual}`); >+} >+ >+function shouldBeNaN(actual) >+{ >+ if (!Number.isNaN(actual)) >+ throw new Error(`bad value: ${actual}`); >+} >+ >+{ >+ let dateValue = Date.parse("275760-09-13T00:00:00.000Z"); >+ shouldBe(dateValue, 8640000000000000); >+ >+ let date = new Date(dateValue); >+ shouldBe(date.getUTCFullYear(), 275760); >+ shouldBe(date.getUTCMonth(), 8); >+ shouldBe(date.getUTCDate(), 13); >+ shouldBe(date.getUTCHours(), 0); >+ shouldBe(date.getUTCMinutes(), 0); >+ shouldBe(date.getUTCSeconds(), 0); >+ shouldBe(date.getUTCMilliseconds(), 0); >+} >+ >+{ >+ let dateValue = Date.UTC(275760, 8, 13, 0, 0, 0, 0); >+ shouldBe(dateValue, 8640000000000000); >+ >+ let date = new Date(dateValue); >+ shouldBe(date.getUTCFullYear(), 275760); >+ shouldBe(date.getUTCMonth(), 8); >+ shouldBe(date.getUTCDate(), 13); >+ shouldBe(date.getUTCHours(), 0); >+ shouldBe(date.getUTCMinutes(), 0); >+ shouldBe(date.getUTCSeconds(), 0); >+ shouldBe(date.getUTCMilliseconds(), 0); >+} >+ >+{ >+ let dateValue = Date.parse("275760-09-12T23:59:59.999Z"); >+ shouldBe(dateValue, 8639999999999999); >+ >+ let date = new Date(dateValue); >+ shouldBe(date.getUTCFullYear(), 275760); >+ shouldBe(date.getUTCMonth(), 8); >+ shouldBe(date.getUTCDate(), 12); >+ shouldBe(date.getUTCHours(), 23); >+ shouldBe(date.getUTCMinutes(), 59); >+ shouldBe(date.getUTCSeconds(), 59); >+ shouldBe(date.getUTCMilliseconds(), 999); >+} >+ >+{ >+ let dateValue = Date.UTC(275760, 8, 12, 23, 59, 59, 999); >+ shouldBe(dateValue, 8639999999999999); >+ >+ let date = new Date(dateValue); >+ shouldBe(date.getUTCFullYear(), 275760); >+ shouldBe(date.getUTCMonth(), 8); >+ shouldBe(date.getUTCDate(), 12); >+ shouldBe(date.getUTCHours(), 23); >+ shouldBe(date.getUTCMinutes(), 59); >+ shouldBe(date.getUTCSeconds(), 59); >+ shouldBe(date.getUTCMilliseconds(), 999); >+} >+ >+{ >+ let dateValue = Date.parse("275760-09-13T00:00:00.001Z"); >+ shouldBeNaN(dateValue); >+} >+ >+{ >+ let dateValue = Date.UTC(275760, 8, 13, 0, 0, 0, 1); >+ shouldBeNaN(dateValue); >+} >+ >+{ >+ let dateValue = Date.parse("-271821-04-20T00:00:00.000Z"); >+ shouldBe(dateValue, -8640000000000000); >+ >+ let date = new Date(dateValue); >+ shouldBe(date.getUTCFullYear(), -271821); >+ shouldBe(date.getUTCMonth(), 3); >+ shouldBe(date.getUTCDate(), 20); >+ shouldBe(date.getUTCHours(), 0); >+ shouldBe(date.getUTCMinutes(), 0); >+ shouldBe(date.getUTCSeconds(), 0); >+ shouldBe(date.getUTCMilliseconds(), 0); >+} >+ >+{ >+ let dateValue = Date.UTC(-271821, 3, 20, 0, 0, 0, 0); >+ shouldBe(dateValue, -8640000000000000); >+ >+ let date = new Date(dateValue); >+ shouldBe(date.getUTCFullYear(), -271821); >+ shouldBe(date.getUTCMonth(), 3); >+ shouldBe(date.getUTCDate(), 20); >+ shouldBe(date.getUTCHours(), 0); >+ shouldBe(date.getUTCMinutes(), 0); >+ shouldBe(date.getUTCSeconds(), 0); >+ shouldBe(date.getUTCMilliseconds(), 0); >+} >+ >+{ >+ let dateValue = Date.parse("-271821-04-20T00:00:00.001Z"); >+ shouldBe(dateValue, -8639999999999999); >+ >+ let date = new Date(dateValue); >+ shouldBe(date.getUTCFullYear(), -271821); >+ shouldBe(date.getUTCMonth(), 3); >+ shouldBe(date.getUTCDate(), 20); >+ shouldBe(date.getUTCHours(), 0); >+ shouldBe(date.getUTCMinutes(), 0); >+ shouldBe(date.getUTCSeconds(), 0); >+ shouldBe(date.getUTCMilliseconds(), 1); >+} >+ >+{ >+ let dateValue = Date.UTC(-271821, 3, 20, 0, 0, 0, 1); >+ shouldBe(dateValue, -8639999999999999); >+ >+ let date = new Date(dateValue); >+ shouldBe(date.getUTCFullYear(), -271821); >+ shouldBe(date.getUTCMonth(), 3); >+ shouldBe(date.getUTCDate(), 20); >+ shouldBe(date.getUTCHours(), 0); >+ shouldBe(date.getUTCMinutes(), 0); >+ shouldBe(date.getUTCSeconds(), 0); >+ shouldBe(date.getUTCMilliseconds(), 1); >+} >+ >+{ >+ let dateValue = Date.parse("-271821-04-19T23:59:59.999Z"); >+ shouldBeNaN(dateValue); >+} >+ >+{ >+ let dateValue = Date.UTC(-271821, 3, 19, 23, 59, 59, 999); >+ shouldBeNaN(dateValue); >+} >Index: Source/WTF/ChangeLog >=================================================================== >--- Source/WTF/ChangeLog (revision 232119) >+++ Source/WTF/ChangeLog (working copy) >@@ -1,3 +1,18 @@ >+2018-05-23 Michael Saboff <msaboff@apple.com> >+ >+ Date.parse() doesn't properly handle input outside of ES Spec limits >+ https://bugs.webkit.org/show_bug.cgi?id=185868 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Clamped date creation to +/-100,000,000 days relative to midnight at the beginning >+ of 01 January, 1970 UTC as per ecma262/#sec-time-values-and-time-range and >+ ecma262/#sec-date-time-string-format. >+ >+ * wtf/DateMath.cpp: >+ (WTF::ymdhmsToSeconds): >+ (WTF::parseES5DateFromNullTerminatedCharacters): >+ > 2018-05-22 Michael Catanzaro <mcatanzaro@igalia.com> > > Prohibit shrinking the FastBitVector >Index: Source/WTF/wtf/DateMath.cpp >=================================================================== >--- Source/WTF/wtf/DateMath.cpp (revision 232119) >+++ Source/WTF/wtf/DateMath.cpp (working copy) >@@ -557,7 +557,13 @@ static inline double ymdhmsToSeconds(int > int mday = firstDayOfMonth[isLeapYear(year)][mon - 1]; > double ydays = daysFrom1970ToYear(year); > >- return (second + minute * secondsPerMinute + hour * secondsPerHour + (mday + day - 1 + ydays) * secondsPerDay); >+ double dateSeconds = second + minute * secondsPerMinute + hour * secondsPerHour + (mday + day - 1 + ydays) * secondsPerDay; >+ >+ // Clamp to EcmaScript standard of +/- 100,000,000 days from 01 January, 1970. >+ if (dateSeconds < -8640000000000.0 || dateSeconds > 8640000000000.0) >+ return std::numeric_limits<double>::quiet_NaN(); >+ >+ return dateSeconds; > } > > // We follow the recommendation of RFC 2822 to consider all >@@ -778,7 +784,7 @@ static char* parseES5TimePortion(char* c > > double parseES5DateFromNullTerminatedCharacters(const char* dateString) > { >- // This parses a date of the form defined in ECMA-262-5, section 15.9.1.15 >+ // This parses a date of the form defined in ecma262/#sec-date-time-string-format > // (similar to RFC 3339 / ISO 8601: YYYY-MM-DDTHH:mm:ss[.sss]Z). > // In most cases it is intentionally strict (e.g. correct field widths, no stray whitespace). >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
mark.lam
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 185868
: 341111