Commit 276c5626 authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

Add date range validity check to the date parser.

Now the parser rejects dates outside the [-8640e12ms, 8640e12ms] range
as specified by ES6 section 20.3.1.1.

Bug: chromium:908248, v8:7781
Change-Id: I3391ce7398c971d54794e5011564a0527794667a
Reviewed-on: https://chromium-review.googlesource.com/c/1350996
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57862}
parent 2fd07376
......@@ -128,13 +128,16 @@ double ParseDateTimeString(Isolate* isolate, Handle<String> str) {
tmp->get(5)->Number(), tmp->get(6)->Number());
double date = MakeDate(day, time);
if (tmp->get(7)->IsNull(isolate)) {
if (!std::isnan(date)) {
if (date >= -DateCache::kMaxTimeBeforeUTCInMs &&
date <= DateCache::kMaxTimeBeforeUTCInMs) {
date = isolate->date_cache()->ToUTC(static_cast<int64_t>(date));
} else {
return std::numeric_limits<double>::quiet_NaN();
}
} else {
date -= tmp->get(7)->Number() * 1000.0;
}
return date;
return DateCache::TimeClip(date);
}
enum ToDateStringMode { kDateOnly, kTimeOnly, kDateAndTime };
......
......@@ -358,3 +358,13 @@ delete Date.prototype.getUTCMilliseconds;
assertTrue(delete Date.prototype.toString);
assertTrue('[object Date]' !== Date());
})();
// Test minimum and maximum date range according to ES6 section 20.3.1.1:
// "The actual range of times supported by ECMAScript Date objects is slightly
// smaller: exactly -100,000,000 days to 100,000,000 days measured relative to
// midnight at the beginning of 01 January, 1970 UTC. This gives a range of
// 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970 UTC."
assertEquals(-8640000000000000, Date.parse("-271821-04-20T00:00:00.000Z"));
assertEquals(8640000000000000, Date.parse("+275760-09-13T00:00:00.000Z"));
assertTrue(isNaN(Date.parse("-271821-04-19T00:00:00.000Z")));
assertTrue(isNaN(Date.parse("+275760-09-14T00:00:00.000Z")));
......@@ -651,9 +651,6 @@
# https://bugs.chromium.org/p/v8/issues/detail?id=6705
'built-ins/Object/assign/strings-and-symbol-order': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7781
'built-ins/Date/parse/time-value-maximum-range': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=7831
'language/statements/generators/generator-created-after-decl-inst': [FAIL],
'language/expressions/generators/generator-created-after-decl-inst': [FAIL],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment