Fix UBsan report in date functions

Found with fuzzer [1]:

  [1]: https://clickhouse-test-reports.s3.yandex.net/19381/95c9e57ec13e450ec6535cf723f504a2e68e3e2c/fuzzer_ubsan/report.html#fail1
This commit is contained in:
Azat Khuzhin 2021-01-23 00:25:49 +03:00
parent eeafd73890
commit f2910deec2
3 changed files with 16 additions and 3 deletions

View File

@ -87,7 +87,7 @@ struct AddMinutesImpl : public AddOnDateTime64DefaultImpl<AddMinutesImpl>
static constexpr auto name = "addMinutes"; static constexpr auto name = "addMinutes";
static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl &) static inline NO_SANITIZE_UNDEFINED UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl &)
{ {
return t + delta * 60; return t + delta * 60;
} }
@ -106,7 +106,7 @@ struct AddHoursImpl : public AddOnDateTime64DefaultImpl<AddHoursImpl>
static constexpr auto name = "addHours"; static constexpr auto name = "addHours";
static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl &) static inline NO_SANITIZE_UNDEFINED UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl &)
{ {
return t + delta * 3600; return t + delta * 3600;
} }
@ -150,7 +150,7 @@ struct AddWeeksImpl : public AddOnDateTime64DefaultImpl<AddWeeksImpl>
static constexpr auto name = "addWeeks"; static constexpr auto name = "addWeeks";
static inline UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone) static inline NO_SANITIZE_UNDEFINED UInt32 execute(UInt32 t, Int64 delta, const DateLUTImpl & time_zone)
{ {
return time_zone.addWeeks(t, delta); return time_zone.addWeeks(t, delta);
} }

View File

@ -0,0 +1,8 @@
-- { echo }
-- tests with INT64_MIN
SELECT addMinutes(toDateTime('2021-01-01 00:00:00', 'GMT'), 9223372036854775808);
2021-01-01 00:00:00
SELECT addHours(toDateTime('2021-01-01 00:00:00', 'GMT'), 9223372036854775808);
2021-01-01 00:00:00
SELECT addWeeks(toDateTime('2021-01-01 00:00:00', 'GMT'), 9223372036854775808);
2021-01-01 00:00:00

View File

@ -0,0 +1,5 @@
-- { echo }
-- tests with INT64_MIN
SELECT addMinutes(toDateTime('2021-01-01 00:00:00', 'GMT'), 9223372036854775808);
SELECT addHours(toDateTime('2021-01-01 00:00:00', 'GMT'), 9223372036854775808);
SELECT addWeeks(toDateTime('2021-01-01 00:00:00', 'GMT'), 9223372036854775808);