Bug #104798 replica fails to read table map events with table name larger than 64 bytes
Submitted: 2 Sep 2021 3:36 Modified: 7 Nov 2021 16:24
Reporter: Song Libing Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:8.0, 8.0.26 OS:Any
Assigned to: CPU Architecture:Any

[2 Sep 2021 3:36] Song Libing
Description:
when table name or db name is larger than 64 bytes, replica and mysqlbinlog fail to read the table map event of the table.  It interrupts replication with error:

 Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, the server was unable to fetch a keyring key required to open an encrypted relay log file, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave. Error_code: MY-013121

How to repeat:
--source include/have_binlog_format_row.inc
--source include/master-slave.inc

--let $name = 测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试
eval CREATE TABLE $name (c1 INT);

eval INSERT INTO $name VALUES(1);

--source include/sync_slave_sql_with_master.inc
eval SELECT * FROM $name;

Suggested fix:
  READER_TRY_SET(m_dblen, read<uint8_t>);
  if (m_dblen > 64 /* NAME_CHAR_LEN */)
    READER_THROW("Database name length too long.")
  ptr_dbnam = READER_TRY_CALL(ptr, m_dblen + 1);
  m_dbnam = std::string(ptr_dbnam, m_dblen);

  READER_TRY_SET(m_tbllen, read<uint8_t>);
  if (m_tbllen > 64 /* NAME_CHAR_LEN */)
    READER_THROW("Table name length too long.")

according to ref manual, db and table identifier can have 64 characters. So it should check character length but not byte length
[2 Sep 2021 3:43] Song Libing
and the error message in the code is not logged anywhere. Suggest to log it into error log for helping troubleshooting.
[2 Sep 2021 6:40] MySQL Verification Team
Hello Libing,

Thank you for the report and test case.
Verified as described.

regards,
Umesh
[2 Sep 2021 6:41] MySQL Verification Team
- 8.0.26
 ./mtr rpl_bug104798
Logging: ./mtr  rpl_bug104798
MySQL Version 8.0.26
Checking supported features
Using 'all' suites
Collecting tests
Checking leftover processes
Removing old var directory
 - WARNING: Using the 'mysql-test/var' symlink
Creating var directory '/export/home/tmp/ushastry/mysql-8.0.26/mysql-test/var'
Installing system database
Using parallel: 1

==============================================================================
                  TEST NAME                       RESULT  TIME (ms) COMMENT
------------------------------------------------------------------------------
[ 50%] main.rpl_bug104798                        [ fail ]
        Test ended at 2021-09-02 08:03:36

.
**** SHOW SLAVE STATUS on slave ****
SHOW SLAVE STATUS;
Slave_IO_State  Waiting for source to send event
Master_Host     127.0.0.1
Master_User     root
Master_Port     13000
Connect_Retry   1
Master_Log_File master-bin.000001
Read_Master_Log_Pos     796
Relay_Log_File  slave-relay-bin.000002
Relay_Log_Pos   652
Relay_Master_Log_File   master-bin.000001
Slave_IO_Running        Yes
Slave_SQL_Running       No
Replicate_Do_DB
Replicate_Ignore_DB
Replicate_Do_Table
Replicate_Ignore_Table
Replicate_Wild_Do_Table
Replicate_Wild_Ignore_Table
Last_Errno      13121
Last_Error      Relay log read failure: Could not parse relay log event entry. The possible reasons are: the master's binary log is corrupted (you can check this by running 'mysqlbinlog' on the binary log), the slave's relay log is corrupted (you can check this by running 'mysqlbinlog' on the relay log), a network problem, the server was unable to fetch a keyring key required to open an encrypted relay log file, or a bug in the master's or slave's MySQL code. If you want to check the master's binary log or slave's relay log, you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.
[6 Sep 2021 9:39] MySQL Verification Team
Bug #104838 marked as duplicate of this one
[3 Nov 2021 12:53] Pedro Gomes
Bug#105258 is marked as duplicate of this bug
[7 Nov 2021 16:24] Margaret Fisher
Posted by developer:
 
Changelog entry added for MySQL 8.0.28:

Replication stopped with an error when reading a table map event if the name of the table or database was over 64 bytes – the limit is 64 characters, so the use of multi-byte characters could cause this situation. The replica now no longer checks the size of the table and database names, and supports the transmission of longer names.