Fix buffer overflow in DateLUT

This commit is contained in:
Alexey Milovidov 2021-01-23 01:58:41 +03:00
parent 303db08231
commit 505898747e
3 changed files with 6 additions and 1 deletions

View File

@ -229,8 +229,12 @@ public:
inline UInt8 daysInMonth(UInt16 year, UInt8 month) const inline UInt8 daysInMonth(UInt16 year, UInt8 month) const
{ {
UInt16 idx = year - DATE_LUT_MIN_YEAR;
if (unlikely(idx >= DATE_LUT_YEARS))
return 31; /// Implementation specific behaviour on overflow.
/// 32 makes arithmetic more simple. /// 32 makes arithmetic more simple.
DayNum any_day_of_month = DayNum(years_lut[year - DATE_LUT_MIN_YEAR] + 32 * (month - 1)); DayNum any_day_of_month = DayNum(years_lut[idx] + 32 * (month - 1));
return lut[any_day_of_month].days_in_month; return lut[any_day_of_month].days_in_month;
} }

View File

@ -0,0 +1 @@
SELECT toDate('2105-12-31') + INTERVAL number MONTH FROM system.numbers LIMIT 25000 FORMAT Null;