1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +03:00

fix(ubsan): MCOL-5844 - iron out UBSAN reports

The most important fix here is the fix of possible buffer overrun in
DATEFORMAT() function. A "%W" format, repeated enough times, would
overflow the 256-bytes buffer for result. Now we use ostringstream to
construct result and we are safe.

Changes in date/time projection functions made me fix difference between
us and server behavior. The new, better behavior is reflected in changes
in tests' results.

Also, there was incorrect logic in TRUNCATE() and ROUND() functions in
computing the decimal "shift."
This commit is contained in:
Serguey Zefirov
2024-11-21 14:52:01 +03:00
committed by Leonid Fedorov
parent 3bcc2e2fda
commit 39a976c39a
26 changed files with 207 additions and 133 deletions

View File

@ -295,14 +295,14 @@ NULL NULL
SELECT t1_dt, DATE_FORMAT(t1_dt, '%Y-%m-%d') a, DATE_FORMAT(t1_d, '%a %D %b %Y') b, DATE_FORMAT(t1_d, '%W %D %M %Y') c FROM t1;
t1_dt a b c
NULL NULL NULL NULL
0000-00-00 00:00:00 0000-00-00 Sun 0th NON_VALID 0000 Sunday 0th NON_VALID 0000
0000-00-00 00:00:00 0000-00-00 NULL NULL
2020-11-11 12:12:12 2020-11-11 Mon 11th Nov 2222 Monday 11th November 2222
2020-12-31 12:34:56 2020-12-31 Wed 1st Jan 2020 Wednesday 1st January 2020
2017-02-01 12:12:12 2017-02-01 Mon 1st Feb 2016 Monday 1st February 2016
SELECT t1_dt, DATE_FORMAT(t1_dt, '%Y/%m/%d %T') a, DATE_FORMAT(t1_dt, '%a %D %b %Y %H:%i') b, DATE_FORMAT(t1_dt, '%W %D %M %Y %T') c FROM t1;
t1_dt a b c
NULL NULL NULL NULL
0000-00-00 00:00:00 0000/00/00 00:00:00 Sun 0th NON_VALID 0000 00:00 Sunday 0th NON_VALID 0000 00:00:00
0000-00-00 00:00:00 0000/00/00 00:00:00 NULL NULL
2020-11-11 12:12:12 2020/11/11 12:12:12 Wed 11th Nov 2020 12:12 Wednesday 11th November 2020 12:12:12
2020-12-31 12:34:56 2020/12/31 12:34:56 Thu 31st Dec 2020 12:34 Thursday 31st December 2020 12:34:56
2017-02-01 12:12:12 2017/02/01 12:12:12 Wed 1st Feb 2017 12:12 Wednesday 1st February 2017 12:12:12
@ -312,14 +312,14 @@ en_US
SELECT t1_dt, DAYNAME(t1_dt), DAYOFWEEK(t1_dt), WEEKDAY(t1_dt) FROM t1;
t1_dt DAYNAME(t1_dt) DAYOFWEEK(t1_dt) WEEKDAY(t1_dt)
NULL NULL NULL NULL
0000-00-00 00:00:00 Sunday 1 6
0000-00-00 00:00:00 NULL NULL NULL
2020-11-11 12:12:12 Wednesday 4 2
2020-12-31 12:34:56 Thursday 5 3
2017-02-01 12:12:12 Wednesday 4 2
SELECT t1_d, DAYNAME(t1_d), DAYOFWEEK(t1_d), WEEKDAY(t1_d) FROM t1;
t1_d DAYNAME(t1_d) DAYOFWEEK(t1_d) WEEKDAY(t1_d)
NULL NULL NULL NULL
0000-00-00 Sunday 1 6
0000-00-00 NULL NULL NULL
2222-11-11 Monday 2 0
2020-01-01 Wednesday 4 2
2016-02-01 Monday 2 0
@ -333,7 +333,7 @@ NULL NULL NULL NULL NULL
SELECT t1_dt, EXTRACT(DAY FROM t1_dt) 'DAY', EXTRACT(YEAR FROM t1_dt) 'YEAR', EXTRACT(MONTH FROM t1_dt) 'MONTH', EXTRACT(WEEK FROM t1_dt) 'WEEK' FROM t1;
t1_dt DAY YEAR MONTH WEEK
NULL NULL NULL NULL NULL
0000-00-00 00:00:00 0 0 0 613566753
0000-00-00 00:00:00 0 0 0 1
2020-11-11 12:12:12 11 2020 11 46
2020-12-31 12:34:56 31 2020 12 53
2017-02-01 12:12:12 1 2017 2 5
@ -361,10 +361,10 @@ NULL NULL
SELECT t1_t, TIMEDIFF('12:58:11', t1_t) FROM t1;
t1_t TIMEDIFF('12:58:11', t1_t)
NULL NULL
00:00:00 838:59:59
12:12:12 838:59:59
11:11:11 838:59:59
11:11:11 838:59:59
00:00:00 12:58:11
12:12:12 00:45:59
11:11:11 01:47:00
11:11:11 01:47:00
SELECT t1_d, t1_dt, TIMESTAMPDIFF(MONTH, t1_d, t1_dt) FROM t1;
t1_d t1_dt TIMESTAMPDIFF(MONTH, t1_d, t1_dt)
NULL NULL NULL
@ -396,7 +396,7 @@ NULL NULL NULL
SELECT t1_d, WEEK(t1_d), t1_dt, WEEK(t1_dt) FROM t1;
t1_d WEEK(t1_d) t1_dt WEEK(t1_dt)
NULL NULL NULL NULL
0000-00-00 613566753 0000-00-00 00:00:00 613566753
0000-00-00 1 0000-00-00 00:00:00 1
2222-11-11 45 2020-11-11 12:12:12 45
2020-01-01 0 2020-12-31 12:34:56 52
2016-02-01 5 2017-02-01 12:12:12 5