Skip to content

Commit d88dfd8

Browse files
committed
MDEV-19350 Server crashes in delete_tree_element / ... / Item_func_group_concat::repack_tree
Item_func_group_concat stores values in `tree`, which is often, but not always the same as `&tree_base`.
1 parent 3fe3857 commit d88dfd8

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

mysql-test/r/func_gconcat.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,3 +1207,22 @@ c
12071207
Warnings:
12081208
Warning 1260 Row 15 was cut by GROUP_CONCAT()
12091209
set max_session_mem_used=default;
1210+
SET group_concat_max_len= 8;
1211+
CREATE TABLE t1 (a INT);
1212+
INSERT t1 VALUES (1),(2);
1213+
CREATE TABLE t2 (b DATE, c INT);
1214+
INSERT t2 VALUES ('2019-12-04',1),('2020-03-28',2);
1215+
CREATE TABLE t3 (d INT);
1216+
INSERT t3 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14);
1217+
CREATE TABLE t4 (e INT);
1218+
INSERT t4 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15);
1219+
SELECT (SELECT MAX(a) FROM t1 WHERE t2_sq.c > 0) AS f,
1220+
GROUP_CONCAT(t2_sq.b ORDER BY 1) AS gc
1221+
FROM (SELECT t2_a.* FROM t2 AS t2_a, t2 AS t2_b) AS t2_sq, t3, t4
1222+
GROUP BY f;
1223+
f gc
1224+
2 2019-12-
1225+
Warnings:
1226+
Warning 1260 Row 1 was cut by GROUP_CONCAT()
1227+
DROP TABLE t1, t2, t3, t4;
1228+
SET group_concat_max_len= default;

mysql-test/t/func_gconcat.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,3 +879,22 @@ set max_session_mem_used=16*1024*1024; # 8M..32M
879879
SELECT GROUP_CONCAT(concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1), concat(seq/1.1) ORDER BY 2,1,3,4,6,5,8,7) AS c
880880
FROM seq_1_to_200000;
881881
set max_session_mem_used=default;
882+
883+
#
884+
# MDEV-19350 Server crashes in delete_tree_element / ... / Item_func_group_concat::repack_tree
885+
#
886+
SET group_concat_max_len= 8;
887+
CREATE TABLE t1 (a INT);
888+
INSERT t1 VALUES (1),(2);
889+
CREATE TABLE t2 (b DATE, c INT);
890+
INSERT t2 VALUES ('2019-12-04',1),('2020-03-28',2);
891+
CREATE TABLE t3 (d INT);
892+
INSERT t3 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14);
893+
CREATE TABLE t4 (e INT);
894+
INSERT t4 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15);
895+
SELECT (SELECT MAX(a) FROM t1 WHERE t2_sq.c > 0) AS f,
896+
GROUP_CONCAT(t2_sq.b ORDER BY 1) AS gc
897+
FROM (SELECT t2_a.* FROM t2 AS t2_a, t2 AS t2_b) AS t2_sq, t3, t4
898+
GROUP BY f;
899+
DROP TABLE t1, t2, t3, t4;
900+
SET group_concat_max_len= default;

sql/item_sum.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3345,8 +3345,8 @@ bool Item_func_group_concat::repack_tree(THD *thd)
33453345
delete_tree(&st.tree);
33463346
return 1;
33473347
}
3348-
delete_tree(&tree_base);
3349-
tree_base= st.tree;
3348+
delete_tree(tree);
3349+
*tree= st.tree;
33503350
tree_len= st.len;
33513351
return 0;
33523352
}

0 commit comments

Comments
 (0)