Skip to content

Commit

Permalink
MDEV-24855 ER_CRASHED_ON_USAGE or Assertion `length <= column->length'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
montywi committed Feb 14, 2021
1 parent b3df194 commit 34c6540
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions mysql-test/main/group_by.result
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,14 @@ v 2v,2v
NULL 1c,2v,2v
DROP TABLE t1,t2;
#
# MDEV-24855 ER_CRASHED_ON_USAGE or Assertion `length <= column->length'
# failed in ma_blockrec.c
#
CREATE TABLE t1 (a BIT(5), c BINARY(179));
INSERT INTO t1 VALUES (b'1100','foo'),(b'0','bar');
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();
DROP TABLE t1;
#
# MDEV-6129: Server crashes during UNION with ORDER BY field IS NULL
#
SET sql_mode='ONLY_FULL_GROUP_BY';
Expand Down
12 changes: 12 additions & 0 deletions mysql-test/main/group_by.test
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,18 @@ FROM t1 JOIN t2 ON c = b GROUP BY b WITH ROLLUP;

DROP TABLE t1,t2;

--echo #
--echo # MDEV-24855 ER_CRASHED_ON_USAGE or Assertion `length <= column->length'
--echo # failed in ma_blockrec.c
--echo #

CREATE TABLE t1 (a BIT(5), c BINARY(179));
INSERT INTO t1 VALUES (b'1100','foo'),(b'0','bar');
--disable_result_log
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();
--enable_result_log
DROP TABLE t1;

--echo #
--echo # MDEV-6129: Server crashes during UNION with ORDER BY field IS NULL
--echo #
Expand Down
8 changes: 3 additions & 5 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18504,9 +18504,9 @@ bool Create_tmp_table::add_fields(THD *thd,
distinct_record_structure= true;
}
li.rewind();
uint uneven_delta= 0;
while ((item=li++))
{
uint uneven_delta;
current_counter= (((param->hidden_field_count < (fieldnr + 1)) &&
distinct_record_structure &&
(!m_with_cycle ||
Expand Down Expand Up @@ -18569,8 +18569,8 @@ bool Create_tmp_table::add_fields(THD *thd,

uneven_delta= m_uneven_bit_length;
add_field(table, new_field, fieldnr++, param->force_not_null_cols);
uneven_delta= m_uneven_bit_length - uneven_delta;
m_field_count[current_counter]++;
m_uneven_bit[current_counter]+= (m_uneven_bit_length - uneven_delta);

if (!(new_field->flags & NOT_NULL_FLAG))
{
Expand Down Expand Up @@ -18651,8 +18651,8 @@ bool Create_tmp_table::add_fields(THD *thd,

uneven_delta= m_uneven_bit_length;
add_field(table, new_field, fieldnr++, param->force_not_null_cols);
uneven_delta= m_uneven_bit_length - uneven_delta;
m_field_count[current_counter]++;
m_uneven_bit[current_counter]+= (m_uneven_bit_length - uneven_delta);

if (item->marker == 4 && item->maybe_null)
{
Expand All @@ -18662,7 +18662,6 @@ bool Create_tmp_table::add_fields(THD *thd,
if (current_counter == distinct)
new_field->flags|= FIELD_PART_OF_TMP_UNIQUE;
}
m_uneven_bit[current_counter]+= uneven_delta;
}
DBUG_ASSERT(fieldnr == m_field_count[other] + m_field_count[distinct]);
DBUG_ASSERT(m_blob_count == m_blobs_count[other] + m_blobs_count[distinct]);
Expand Down Expand Up @@ -18821,7 +18820,6 @@ bool Create_tmp_table::finalize(THD *thd,

if (!(field->flags & NOT_NULL_FLAG))
{

recinfo->null_bit= (uint8)1 << (null_counter[current_counter] & 7);
recinfo->null_pos= (null_pack_base[current_counter] +
null_counter[current_counter]/8);
Expand Down

0 comments on commit 34c6540

Please sign in to comment.