From 07f031ec8a26d0ee7081d725fe59b312101bcae8 Mon Sep 17 00:00:00 2001 From: Yarik Briukhovetskyi <114298166+yariks5s@users.noreply.github.com> Date: Mon, 8 Jan 2024 15:34:22 +0100 Subject: [PATCH] fix fuzzer --- src/Functions/DateTimeTransforms.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Functions/DateTimeTransforms.h b/src/Functions/DateTimeTransforms.h index e9cee9616fb..dd843daed8c 100644 --- a/src/Functions/DateTimeTransforms.h +++ b/src/Functions/DateTimeTransforms.h @@ -20,6 +20,7 @@ namespace DB { +static Int64 Int64_max_value = std::numeric_limits::max(); static constexpr auto microsecond_multiplier = 1000000; static constexpr auto millisecond_multiplier = 1000; @@ -698,8 +699,8 @@ struct ToStartOfInterval return time_zone.toStartOfWeekInterval(time_zone.toDayNum(t / scale_multiplier), weeks); else { - if (const auto weeks_to_days = weeks * 7; weeks_to_days / 7 == weeks) // Check if multiplication doesn't overflow Int64 value - return ToStartOfInterval::execute(t, weeks_to_days, time_zone, scale_multiplier, origin); + if (weeks < Int64_max_value / 7) // Check if multiplication doesn't overflow Int64 value + return ToStartOfInterval::execute(t, weeks * 7, time_zone, scale_multiplier, origin); else throw Exception(ErrorCodes::VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE, "Value {} * 7 is out of bounds for type Int64", weeks); } @@ -760,8 +761,8 @@ struct ToStartOfInterval return time_zone.toStartOfQuarterInterval(time_zone.toDayNum(t / scale_multiplier), quarters); else { - if (const auto quarters_to_months = quarters * 3; quarters_to_months / 3 == quarters) // Check if multiplication doesn't overflow Int64 value - return ToStartOfInterval::execute(t, quarters_to_months, time_zone, scale_multiplier, origin); + if (quarters < Int64_max_value / 3) // Check if multiplication doesn't overflow Int64 value + return ToStartOfInterval::execute(t, quarters * 3, time_zone, scale_multiplier, origin); else throw Exception(ErrorCodes::VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE, "Value {} * 3 is out of bounds for type Int64", quarters); } @@ -789,8 +790,8 @@ struct ToStartOfInterval return time_zone.toStartOfYearInterval(time_zone.toDayNum(t / scale_multiplier), years); else { - if (const auto years_to_months = years * 12; years_to_months / 12 == years) // Check if multiplication doesn't overflow Int64 value - return ToStartOfInterval::execute(t, years_to_months, time_zone, scale_multiplier, origin); + if (years < Int64_max_value / 12) // Check if multiplication doesn't overflow Int64 value + return ToStartOfInterval::execute(t, years * 12, time_zone, scale_multiplier, origin); else throw Exception(ErrorCodes::VALUE_IS_OUT_OF_RANGE_OF_DATA_TYPE, "Value {} * 12 is out of bounds for type Int64", years); }