Skip to content

Commit 2e4de1f

Browse files
authored
Merge pull request #60419 from Avogar/fix-ub-setting
Fix undefined-behavior in case of too big max_execution_time setting
2 parents 54ae88a + 0b2e678 commit 2e4de1f

3 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/Core/SettingsFields.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace ErrorCodes
2121
extern const int CANNOT_PARSE_BOOL;
2222
extern const int CANNOT_PARSE_NUMBER;
2323
extern const int CANNOT_CONVERT_TYPE;
24+
extern const int BAD_ARGUMENTS;
2425
}
2526

2627

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

tests/queries/0_stateless/03000_too_big_max_execution_time_setting.reference

Whitespace-only changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
select 1 settings max_execution_time = 9223372036854775808; -- {clientError BAD_ARGUMENTS}
2+

0 commit comments

Comments
 (0)