Skip to content

Commit 90c4dff

Browse files
author
Alexey Botchkov
committed
MDEV-25178 JSON_TABLE: ASAN use-after-poison in my_fill_8bit Json_table_column::On_response::respond.
table record buffer size was smaller than required when the charset changes.
1 parent 6f56458 commit 90c4dff

File tree

4 files changed

+28
-11
lines changed

4 files changed

+28
-11
lines changed

mysql-test/suite/json/r/json_table.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,5 +516,11 @@ a b
516516
NULL NULL
517517
DROP VIEW v;
518518
#
519+
# MDEV-25178 JSON_TABLE: ASAN use-after-poison in my_fill_8bit / Json_table_column::On_response::respond
520+
#
521+
SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(a CHAR(100) PATH '$' DEFAULT "0" ON ERROR)) AS jt;
522+
a
523+
0
524+
#
519525
# End of 10.6 tests
520526
#

mysql-test/suite/json/t/json_table.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,11 @@ SHOW CREATE VIEW v;
395395
SELECT * FROM v;
396396
DROP VIEW v;
397397

398+
--echo #
399+
--echo # MDEV-25178 JSON_TABLE: ASAN use-after-poison in my_fill_8bit / Json_table_column::On_response::respond
400+
--echo #
401+
SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(a CHAR(100) PATH '$' DEFAULT "0" ON ERROR)) AS jt;
402+
398403
--echo #
399404
--echo # End of 10.6 tests
400405
--echo #

sql/field.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,8 @@ class Field: public Value_source
16111611
virtual longlong val_time_packed(THD *thd);
16121612
virtual const TYPELIB *get_typelib() const { return NULL; }
16131613
virtual CHARSET_INFO *charset() const= 0;
1614-
virtual void change_charset(const DTCollation &new_cs) {}
1614+
/* returns TRUE if the new charset differs. */
1615+
virtual bool change_charset(const DTCollation &new_cs) { return FALSE; }
16151616
virtual const DTCollation &dtcollation() const= 0;
16161617
virtual CHARSET_INFO *charset_for_protocol(void) const
16171618
{ return binary() ? &my_charset_bin : charset(); }
@@ -2110,11 +2111,16 @@ class Field_str :public Field {
21102111
{
21112112
return m_collation;
21122113
}
2113-
void change_charset(const DTCollation &new_cs) override
2114+
bool change_charset(const DTCollation &new_cs) override
21142115
{
2115-
field_length= (field_length * new_cs.collation->mbmaxlen) /
2116-
m_collation.collation->mbmaxlen;
2117-
m_collation= new_cs;
2116+
if (m_collation.collation != new_cs.collation)
2117+
{
2118+
field_length= (field_length * new_cs.collation->mbmaxlen) /
2119+
m_collation.collation->mbmaxlen;
2120+
m_collation= new_cs;
2121+
return TRUE;
2122+
}
2123+
return FALSE;
21182124
}
21192125
bool binary() const override { return field_charset() == &my_charset_bin; }
21202126
uint32 max_display_length() const override { return field_length; }

sql/json_table.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ bool Create_json_table::add_json_table_fields(THD *thd, TABLE *table,
811811
*/
812812
sql_f->length= sql_f->char_length;
813813
if (!(jc->m_explicit_cs= sql_f->charset))
814-
sql_f->charset= thd->variables.collation_server;
814+
sql_f->charset= &my_charset_utf8mb4_bin;
815815

816816
if (sql_f->prepare_stage1(thd, thd->mem_root, table->file,
817817
table->file->ha_table_flags()))
@@ -1148,12 +1148,12 @@ int Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table,
11481148
Json_table_column *jc= jc_i++;
11491149
uint32 old_pack_length= f->pack_length();
11501150

1151-
f->change_charset(
1152-
jc->m_explicit_cs ? jc->m_explicit_cs : m_json->collation);
1153-
1154-
if (field_offset)
1151+
if (f->change_charset(
1152+
jc->m_explicit_cs ? jc->m_explicit_cs : m_json->collation) ||
1153+
field_offset)
11551154
{
1156-
f->move_field(f->ptr + field_offset, f->null_ptr, f->null_bit);
1155+
if (field_offset)
1156+
f->move_field(f->ptr + field_offset, f->null_ptr, f->null_bit);
11571157
f->reset();
11581158
}
11591159

0 commit comments

Comments
 (0)