From 9be0a0fd28a295200f6e5377c37b8f454aab79db Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 15 Jan 2022 17:37:36 -0500 Subject: [PATCH] LibJS: Protect YearFromTime against non-finite times --- Userland/Libraries/LibJS/Runtime/Date.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 152870d0f6..484191ff5d 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -5,6 +5,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -147,6 +148,8 @@ double time_from_year(i32 y) i32 year_from_time(double t) { // the largest integral Number y (closest to +∞) such that TimeFromYear(y) ≤ t + if (!Value(t).is_finite_number()) + return NumericLimits::max(); // Approximation using average number of milliseconds per year. We might have to adjust this guess afterwards. auto year = static_cast(t / (365.2425 * Date::ms_per_day) + 1970);