Skip to content

Commit

Permalink
Editorial: Avoid hitting assertion in GetUTCEpochNanoseconds
Browse files Browse the repository at this point in the history
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: #2729
  • Loading branch information
ptomato authored and Ms2ger committed Jan 8, 2024
1 parent 42eca97 commit c4b17d8
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions spec/instant.html
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ <h1>ToTemporalInstant ( _item_ )</h1>
1. If _item_ is not a String, throw a *TypeError* exception.
1. Let _parsed_ be ? ParseTemporalInstantString(_item_).
1. If _parsed_.[[Z]] is *true*, let _offsetNanoseconds_ be 0; otherwise, let _offsetNanoseconds_ be ! ParseDateTimeUTCOffset(_parsed_.[[OffsetString]]).
1. If abs(ISODateToEpochDays(_parsed_.[[Year]], _parsed_.[[Month]] - 1, _parsed_.[[Day]])) > 10<sup>8</sup>, throw a *RangeError* exception.
1. Let _epochNanoseconds_ be GetUTCEpochNanoseconds(_parsed_.[[Year]], _parsed_.[[Month]], _parsed_.[[Day]], _parsed_.[[Hour]], _parsed_.[[Minute]], _parsed_.[[Second]], _parsed_.[[Millisecond]], _parsed_.[[Microsecond]], _parsed_.[[Nanosecond]], _offsetNanoseconds_).
1. If IsValidEpochNanoseconds(_epochNanoseconds_) is *false*, throw a *RangeError* exception.
1. Return ! CreateTemporalInstant(_epochNanoseconds_).
Expand Down
1 change: 1 addition & 0 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ <h1>
</emu-note>
<emu-alg>
1. Assert: IsValidISODate(_year_, _month_, _day_) is *true*.
1. If abs(ISODateToEpochDays(_year_, _month_ - 1, _day_)) > 10<sup>8</sup> + 1, return *false*.
1. Let _ns_ be ℝ(GetUTCEpochNanoseconds(_year_, _month_, _day_, _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_)).
1. If _ns_ &le; nsMinInstant - nsPerDay, then
1. Return *false*.
Expand Down

0 comments on commit c4b17d8

Please sign in to comment.