Merge pull request #23278 from kitaisreal/to-date-time-decimal-overflow-ubsan-fix

Function toDateTime decimal overflow ubsan fix
This commit is contained in:
Maksim Kita 2021-04-19 10:12:24 +03:00 committed by GitHub
commit 2f56f8d040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

View File

@ -103,7 +103,10 @@ inline DecimalType decimalFromComponentsWithMultiplier(
if (common::mulOverflow(whole, scale_multiplier, whole_scaled))
throw Exception("Decimal math overflow", ErrorCodes::DECIMAL_OVERFLOW);
const T value = whole_scaled + fractional_sign * (fractional % scale_multiplier);
T value;
if (common::addOverflow(whole_scaled, fractional_sign * (fractional % scale_multiplier), value))
throw Exception("Decimal math overflow", ErrorCodes::DECIMAL_OVERFLOW);
return DecimalType(value);
}

View File

@ -0,0 +1,2 @@
SELECT toDateTime('9223372036854775806', 7); -- { serverError 407 }
SELECT toDateTime('9223372036854775806', 8); -- { serverError 407 }