From 615287ae75b6bdb1c89f4f279e6b99b76dfc4f41 Mon Sep 17 00:00:00 2001 From: fenglv Date: Sun, 22 Nov 2020 03:42:16 +0000 Subject: [PATCH] Avoid bigint_cast stack overflow --- base/common/wide_integer_impl.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/base/common/wide_integer_impl.h b/base/common/wide_integer_impl.h index 2a889819c11..e1e6a949273 100644 --- a/base/common/wide_integer_impl.h +++ b/base/common/wide_integer_impl.h @@ -239,6 +239,13 @@ struct integer::_impl template constexpr static void set_multiplier(integer & self, T t) noexcept { constexpr uint64_t max_int = std::numeric_limits::max(); + + /// Replacing nan to zero, and inf to max(T) to avoid stack overflow in bigint_cast + if (isnan(t)) + t = 0; + if (isinf(t)) + t = std::numeric_limits::max(); + const T alpha = t / max_int; if (alpha <= max_int)