Skip to content

Commit 6c30bc2

Browse files
committed
MDEV-22268 virtual longlong Item_func_div::int_op(): Assertion `0' failed in Item_func_div::int_op
Item_func_div::fix_length_and_dec_temporal() set the return data type to integer in case of @div_precision_increment==0 for temporal input with FSP=0. This caused Item_func_div to call int_op(), which is not implemented, so a crash on DBUG_ASSERT(0) happened. Fixing fix_length_and_dec_temporal() to set the result type to DECIMAL.
1 parent 81a08c5 commit 6c30bc2

File tree

4 files changed

+61
-7
lines changed

4 files changed

+61
-7
lines changed

mysql-test/main/func_math.result

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2251,5 +2251,35 @@ SELECT ROUND( i, 18446744073709551594 ) AS f FROM t1;
22512251
f
22522252
DROP TABLE t1;
22532253
#
2254+
# MDEV-22268 virtual longlong Item_func_div::int_op(): Assertion `0' failed in Item_func_div::int_op
2255+
#
2256+
SET sql_mode='';
2257+
SET @@SESSION.div_precision_increment=0;
2258+
SELECT UTC_TIME / 0;
2259+
UTC_TIME / 0
2260+
NULL
2261+
SELECT TIMESTAMP'2001-01-01 00:00:00'/0;
2262+
TIMESTAMP'2001-01-01 00:00:00'/0
2263+
NULL
2264+
SELECT TIME'00:00:00'/0;
2265+
TIME'00:00:00'/0
2266+
NULL
2267+
CREATE TABLE t1 AS SELECT
2268+
UTC_TIME / 0 AS c1,
2269+
TIMESTAMP'2001-01-01 00:00:00'/0 AS c3,
2270+
TIME'00:00:00'/0 AS c4;
2271+
SHOW CREATE TABLE t1;
2272+
Table Create Table
2273+
t1 CREATE TABLE `t1` (
2274+
`c1` decimal(7,0) DEFAULT NULL,
2275+
`c3` decimal(14,0) DEFAULT NULL,
2276+
`c4` decimal(7,0) DEFAULT NULL
2277+
) ENGINE=MyISAM DEFAULT CHARSET=latin1
2278+
DROP TABLE t1;
2279+
SELECT(-0 * MOD((UTC_TIME / -0)MOD (ATAN('<img src_x0=x onerror="javascript:alert(0)">') MOD COT(0)),-0)) MOD (0 DIV 0);
2280+
ERROR 22003: DOUBLE value is out of range in 'cot(0)'
2281+
SET @@SESSION.div_precision_increment=DEFAULT;
2282+
SET sql_mode=DEFAULT;
2283+
#
22542284
# End of 10.3 tests
22552285
#

mysql-test/main/func_math.test

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,29 @@ CREATE TABLE t1 (i INT(23));
11111111
SELECT ROUND( i, 18446744073709551594 ) AS f FROM t1;
11121112
DROP TABLE t1;
11131113

1114+
1115+
--echo #
1116+
--echo # MDEV-22268 virtual longlong Item_func_div::int_op(): Assertion `0' failed in Item_func_div::int_op
1117+
--echo #
1118+
1119+
SET sql_mode='';
1120+
SET @@SESSION.div_precision_increment=0;
1121+
SELECT UTC_TIME / 0;
1122+
SELECT TIMESTAMP'2001-01-01 00:00:00'/0;
1123+
SELECT TIME'00:00:00'/0;
1124+
CREATE TABLE t1 AS SELECT
1125+
UTC_TIME / 0 AS c1,
1126+
TIMESTAMP'2001-01-01 00:00:00'/0 AS c3,
1127+
TIME'00:00:00'/0 AS c4;
1128+
SHOW CREATE TABLE t1;
1129+
DROP TABLE t1;
1130+
1131+
--error ER_DATA_OUT_OF_RANGE
1132+
SELECT(-0 * MOD((UTC_TIME / -0)MOD (ATAN('<img src_x0=x onerror="javascript:alert(0)">') MOD COT(0)),-0)) MOD (0 DIV 0);
1133+
1134+
SET @@SESSION.div_precision_increment=DEFAULT;
1135+
SET sql_mode=DEFAULT;
1136+
11141137
--echo #
11151138
--echo # End of 10.3 tests
11161139
--echo #

sql/item_func.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,11 +754,11 @@ class Item_num_op :public Item_func_numhybrid
754754
decimals= 0;
755755
set_handler(type_handler_long_or_longlong());
756756
}
757-
void fix_length_and_dec_temporal()
757+
void fix_length_and_dec_temporal(bool downcast_decimal_to_int)
758758
{
759759
set_handler(&type_handler_newdecimal);
760760
fix_length_and_dec_decimal();
761-
if (decimals == 0)
761+
if (decimals == 0 && downcast_decimal_to_int)
762762
set_handler(type_handler_long_or_longlong());
763763
}
764764
bool need_parentheses_in_default() { return true; }

sql/sql_type.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,7 +4772,7 @@ bool Type_handler_decimal_result::
47724772
bool Type_handler_temporal_result::
47734773
Item_func_plus_fix_length_and_dec(Item_func_plus *item) const
47744774
{
4775-
item->fix_length_and_dec_temporal();
4775+
item->fix_length_and_dec_temporal(true);
47764776
return false;
47774777
}
47784778

@@ -4821,7 +4821,7 @@ bool Type_handler_decimal_result::
48214821
bool Type_handler_temporal_result::
48224822
Item_func_minus_fix_length_and_dec(Item_func_minus *item) const
48234823
{
4824-
item->fix_length_and_dec_temporal();
4824+
item->fix_length_and_dec_temporal(true);
48254825
return false;
48264826
}
48274827

@@ -4870,7 +4870,7 @@ bool Type_handler_decimal_result::
48704870
bool Type_handler_temporal_result::
48714871
Item_func_mul_fix_length_and_dec(Item_func_mul *item) const
48724872
{
4873-
item->fix_length_and_dec_temporal();
4873+
item->fix_length_and_dec_temporal(true);
48744874
return false;
48754875
}
48764876

@@ -4919,7 +4919,8 @@ bool Type_handler_decimal_result::
49194919
bool Type_handler_temporal_result::
49204920
Item_func_div_fix_length_and_dec(Item_func_div *item) const
49214921
{
4922-
item->fix_length_and_dec_temporal();
4922+
// Item_func_div::int_op() is not implemented. Disallow DECIMAL->INT downcast.
4923+
item->fix_length_and_dec_temporal(false);
49234924
return false;
49244925
}
49254926

@@ -4968,7 +4969,7 @@ bool Type_handler_decimal_result::
49684969
bool Type_handler_temporal_result::
49694970
Item_func_mod_fix_length_and_dec(Item_func_mod *item) const
49704971
{
4971-
item->fix_length_and_dec_temporal();
4972+
item->fix_length_and_dec_temporal(true);
49724973
return false;
49734974
}
49744975

0 commit comments

Comments
 (0)