mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-21 02:08:12 +03:00
LibJS: Protect YearFromTime against non-finite times
This commit is contained in:
parent
8ad043fe5e
commit
9be0a0fd28
Notes:
sideshowbarker
2024-07-17 20:47:35 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/9be0a0fd28a Pull-request: https://github.com/SerenityOS/serenity/pull/11930 Reviewed-by: https://github.com/linusg ✅
@ -5,6 +5,7 @@
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/NumericLimits.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Time.h>
|
||||
#include <LibCore/DateTime.h>
|
||||
@ -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<i32>::max();
|
||||
|
||||
// Approximation using average number of milliseconds per year. We might have to adjust this guess afterwards.
|
||||
auto year = static_cast<i32>(t / (365.2425 * Date::ms_per_day) + 1970);
|
||||
|
Loading…
Reference in New Issue
Block a user