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.
This commit is contained in:
Timothy Flynn 2022-01-15 10:18:58 -05:00 committed by Linus Groh
parent b2aa3c9f84
commit 62dc9958f5
Notes: sideshowbarker 2024-07-17 20:51:06 +09:00

View File

@ -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;
}