Fix undefined-behavior in case of too big max_execution_time setting

This commit is contained in:
avogar 2024-02-26 14:40:51 +00:00
parent 2c766cf75f
commit 73bbc08384
3 changed files with 7 additions and 0 deletions

View File

@ -21,6 +21,7 @@ namespace ErrorCodes
extern const int CANNOT_PARSE_BOOL;
extern const int CANNOT_PARSE_NUMBER;
extern const int CANNOT_CONVERT_TYPE;
extern const int BAD_ARGUMENTS;
}
@ -268,6 +269,10 @@ namespace
if (d != 0.0 && !std::isnormal(d))
throw Exception(
ErrorCodes::CANNOT_PARSE_NUMBER, "A setting's value in seconds must be a normal floating point number or zero. Got {}", d);
if (d * 1000000 > std::numeric_limits<Poco::Timespan::TimeDiff>::max() || d * 1000000 < std::numeric_limits<Poco::Timespan::TimeDiff>::min())
throw Exception(
ErrorCodes::BAD_ARGUMENTS, "Cannot convert seconds to microseconds: the setting's value in seconds is too big: {}", d);
return static_cast<Poco::Timespan::TimeDiff>(d * 1000000);
}

View File

@ -0,0 +1,2 @@
select 1 settings max_execution_time = 9223372036854775808; -- {clientError CANNOT_PARSE_NUMBER}