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:
parent
b2aa3c9f84
commit
62dc9958f5
Notes:
sideshowbarker
2024-07-17 20:51:06 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/62dc9958f5e Pull-request: https://github.com/SerenityOS/serenity/pull/11913 Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/nico
1 changed files with 2 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue