diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-01-15 10:18:58 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-15 20:13:48 +0100 |
commit | 62dc9958f5e985243af8e8e602667855758f409f (patch) | |
tree | 1a8d70d22a76d6034b8f5e955b78d93e9c769c17 /Userland | |
parent | b2aa3c9f84262c710c78196342652c491493cf7d (diff) | |
download | serenity-62dc9958f5e985243af8e8e602667855758f409f.zip |
LibJS: Protect LocalTZA against non-finite times
It is undefined behavior to cast from a double to an integer if the
value does not fit in the limits of the integer.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Date.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 67347545a8..14683138a9 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -331,7 +331,8 @@ double local_tza(double time, [[maybe_unused]] bool is_utc, Optional<StringView> // UTC measured in milliseconds at local time represented by Number tlocal. When the result is subtracted // from tlocal, it should yield the corresponding time value tUTC. - auto maybe_offset = TimeZone::get_time_zone_offset(time_zone, AK::Time::from_milliseconds(time)); + auto time_since_epoch = Value(time).is_finite_number() ? AK::Time::from_milliseconds(time) : AK::Time::max(); + auto maybe_offset = TimeZone::get_time_zone_offset(time_zone, time_since_epoch); return maybe_offset.value_or(0) * 1000; } |