Skip to content

Commit 34c6540

Browse files
committed
MDEV-24855 ER_CRASHED_ON_USAGE or Assertion `length <= column->length'
When creating a summary temporary table with bit fields used in the sum expression with several parameters, like GROUP_CONCAT(), the counting of bits needed in the record was wrong. The reason we got an assert in Aria was because the bug caused a memory overwrite in the record and Aria noticed that the data was 'impossible.
1 parent b3df194 commit 34c6540

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

mysql-test/main/group_by.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,6 +2612,14 @@ v 2v,2v
26122612
NULL 1c,2v,2v
26132613
DROP TABLE t1,t2;
26142614
#
2615+
# MDEV-24855 ER_CRASHED_ON_USAGE or Assertion `length <= column->length'
2616+
# failed in ma_blockrec.c
2617+
#
2618+
CREATE TABLE t1 (a BIT(5), c BINARY(179));
2619+
INSERT INTO t1 VALUES (b'1100','foo'),(b'0','bar');
2620+
SELECT c, GROUP_CONCAT(CASE NULL WHEN 0 THEN a END, CASE 'foo' WHEN c THEN 1 END) AS f FROM t1 GROUP BY ExtractValue('<a></a>', '/a'), UUID();
2621+
DROP TABLE t1;
2622+
#
26152623
# MDEV-6129: Server crashes during UNION with ORDER BY field IS NULL
26162624
#
26172625
SET sql_mode='ONLY_FULL_GROUP_BY';

mysql-test/main/group_by.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,6 +1716,18 @@ FROM t1 JOIN t2 ON c = b GROUP BY b WITH ROLLUP;
17161716

17171717
DROP TABLE t1,t2;
17181718

1719+
--echo #
1720+
--echo # MDEV-24855 ER_CRASHED_ON_USAGE or Assertion `length <= column->length'
1721+
--echo # failed in ma_blockrec.c
1722+
--echo #
1723+
1724+
CREATE TABLE t1 (a BIT(5), c BINARY(179));
1725+
INSERT INTO t1 VALUES (b'1100','foo'),(b'0','bar');
1726+
--disable_result_log
1727+
SELECT c, GROUP_CONCAT(CASE NULL WHEN 0 THEN a END, CASE 'foo' WHEN c THEN 1 END) AS f FROM t1 GROUP BY ExtractValue('<a></a>', '/a'), UUID();
1728+
--enable_result_log
1729+
DROP TABLE t1;
1730+
17191731
--echo #
17201732
--echo # MDEV-6129: Server crashes during UNION with ORDER BY field IS NULL
17211733
--echo #

sql/sql_select.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18504,9 +18504,9 @@ bool Create_tmp_table::add_fields(THD *thd,
1850418504
distinct_record_structure= true;
1850518505
}
1850618506
li.rewind();
18507-
uint uneven_delta= 0;
1850818507
while ((item=li++))
1850918508
{
18509+
uint uneven_delta;
1851018510
current_counter= (((param->hidden_field_count < (fieldnr + 1)) &&
1851118511
distinct_record_structure &&
1851218512
(!m_with_cycle ||
@@ -18569,8 +18569,8 @@ bool Create_tmp_table::add_fields(THD *thd,
1856918569

1857018570
uneven_delta= m_uneven_bit_length;
1857118571
add_field(table, new_field, fieldnr++, param->force_not_null_cols);
18572-
uneven_delta= m_uneven_bit_length - uneven_delta;
1857318572
m_field_count[current_counter]++;
18573+
m_uneven_bit[current_counter]+= (m_uneven_bit_length - uneven_delta);
1857418574

1857518575
if (!(new_field->flags & NOT_NULL_FLAG))
1857618576
{
@@ -18651,8 +18651,8 @@ bool Create_tmp_table::add_fields(THD *thd,
1865118651

1865218652
uneven_delta= m_uneven_bit_length;
1865318653
add_field(table, new_field, fieldnr++, param->force_not_null_cols);
18654-
uneven_delta= m_uneven_bit_length - uneven_delta;
1865518654
m_field_count[current_counter]++;
18655+
m_uneven_bit[current_counter]+= (m_uneven_bit_length - uneven_delta);
1865618656

1865718657
if (item->marker == 4 && item->maybe_null)
1865818658
{
@@ -18662,7 +18662,6 @@ bool Create_tmp_table::add_fields(THD *thd,
1866218662
if (current_counter == distinct)
1866318663
new_field->flags|= FIELD_PART_OF_TMP_UNIQUE;
1866418664
}
18665-
m_uneven_bit[current_counter]+= uneven_delta;
1866618665
}
1866718666
DBUG_ASSERT(fieldnr == m_field_count[other] + m_field_count[distinct]);
1866818667
DBUG_ASSERT(m_blob_count == m_blobs_count[other] + m_blobs_count[distinct]);
@@ -18821,7 +18820,6 @@ bool Create_tmp_table::finalize(THD *thd,
1882118820

1882218821
if (!(field->flags & NOT_NULL_FLAG))
1882318822
{
18824-
1882518823
recinfo->null_bit= (uint8)1 << (null_counter[current_counter] & 7);
1882618824
recinfo->null_pos= (null_pack_base[current_counter] +
1882718825
null_counter[current_counter]/8);

0 commit comments

Comments
 (0)