Skip to content

Commit c4b17d8

Browse files
ptomatoMs2ger
authored andcommitted
Editorial: Avoid hitting assertion in GetUTCEpochNanoseconds
GetUTCEpochNanoseconds has an assertion that MakeDate, MakeTime, and MakeDay all result in a finite value. However, several places call GetUTCEpochNanoseconds with a year value that may be excessively large, notably from parsing an ISO string such as +999999-01-01, which would cause that assertion to be hit. Add checks in the appropriate places to make sure that the year value is not excessively large. Closes: tc39#2729
1 parent 42eca97 commit c4b17d8

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

spec/instant.html

+1
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ <h1>ToTemporalInstant ( _item_ )</h1>
523523
1. If _item_ is not a String, throw a *TypeError* exception.
524524
1. Let _parsed_ be ? ParseTemporalInstantString(_item_).
525525
1. If _parsed_.[[Z]] is *true*, let _offsetNanoseconds_ be 0; otherwise, let _offsetNanoseconds_ be ! ParseDateTimeUTCOffset(_parsed_.[[OffsetString]]).
526+
1. If abs(ISODateToEpochDays(_parsed_.[[Year]], _parsed_.[[Month]] - 1, _parsed_.[[Day]])) > 10<sup>8</sup>, throw a *RangeError* exception.
526527
1. Let _epochNanoseconds_ be GetUTCEpochNanoseconds(_parsed_.[[Year]], _parsed_.[[Month]], _parsed_.[[Day]], _parsed_.[[Hour]], _parsed_.[[Minute]], _parsed_.[[Second]], _parsed_.[[Millisecond]], _parsed_.[[Microsecond]], _parsed_.[[Nanosecond]], _offsetNanoseconds_).
527528
1. If IsValidEpochNanoseconds(_epochNanoseconds_) is *false*, throw a *RangeError* exception.
528529
1. Return ! CreateTemporalInstant(_epochNanoseconds_).

spec/plaindatetime.html

+1
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ <h1>
941941
</emu-note>
942942
<emu-alg>
943943
1. Assert: IsValidISODate(_year_, _month_, _day_) is *true*.
944+
1. If abs(ISODateToEpochDays(_year_, _month_ - 1, _day_)) > 10<sup>8</sup> + 1, return *false*.
944945
1. Let _ns_ be ℝ(GetUTCEpochNanoseconds(_year_, _month_, _day_, _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_)).
945946
1. If _ns_ &le; nsMinInstant - nsPerDay, then
946947
1. Return *false*.

0 commit comments

Comments
 (0)