Bug #106010 MySQL client disconnects during select-replace with backslash-escaped string
Submitted: 30 Dec 2021 12:11 Modified: 4 Jan 2022 8:22
Reporter: Jan Ingvoldstad Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.7.36 OS:Linux (Slackware 14.2)
Assigned to: MySQL Verification Team CPU Architecture:x86 (Xeon E5)

[30 Dec 2021 12:11] Jan Ingvoldstad
Description:
When selecting the same column twice, once with replace() and aliased and once without, in the same select statement, replacing a backslash-escaped string with a where-like clause containing a backslash-escaped string, results in a disconnect.

The error does not occur if there is no where clause or the column is aliased for both result columns.

The error does not occur when using a MariaDB 10.5 client, only with a MySQL 5.7.36 client.

How to repeat:
MySQL community server version 5.7.36, with MySQL command line client "mysql" connected to localhost via Unix socket.

Server and db characterset: latin1
Server and db collation: latin1_danish_ci
Client and connection characterset: utf8

CREATE TABLE text_test (esc_string varchar(120));
INSERT INTO text_test (esc_string) VALUES ('abc\\/def');
SELECT esc_string,replace(esc_string,'\\/','/') as new_esc_string FROM text_test WHERE esc_string LIKE '%\\\\%';

This results in a zero size result set and disconnect, or direct disconnect, with the error:

ERROR 2013 (HY000): Lost connection to MySQL server during query

The following do not result in disconnects, and return results:

SELECT esc_string as old_esc_string,replace(esc_string,'\\/','/') as new_esc_string FROM text_test WHERE esc_string LIKE '%\\\\%';

SELECT replace(esc_string,'\\/','/') as new_esc_string FROM text_test WHERE esc_string LIKE '%\\\\%';

SELECT esc_string FROM text_test WHERE esc_string LIKE '%\\\\%';

SELECT esc_string,replace(esc_string,'\\/','/') as new_esc_string FROM text_test;
[30 Dec 2021 12:15] Jan Ingvoldstad
The following also does NOT disconnect, it returns the correct result set:

SELECT esc_string,replace(esc_string,'\\/','/') as new_esc_string FROM text_test WHERE esc_string LIKE '%\\\\/%';
[31 Dec 2021 5:26] MySQL Verification Team
Hi,

I am having issue reproducing this. Can you tell me exact my.cnf you use to start your mysqld and what parameters you use with mysql client as following your requirements with latin1 and danis collation and utf8 client I cannot reproduce this on linux neither with 5.7 nor 8.0

Thanks
[4 Jan 2022 8:22] Jan Ingvoldstad
I forgot to state that the build of MySQL 5.7.36 used, is mysql-5.7.36-linux-glibc2.12-x86_64.tar.gz downloaded from https://dev.mysql.com/downloads/file/?id=507442

Client parameters:

mysql -uroot -p

Server startup:

mysqld_safe &

my.cnf content:

[mysqld]
user=mysql
max_connections=1000
max_connect_errors=50000
max_allowed_packet=32M
query_cache_type=0
query_cache_size=512M
query_cache_limit=4M
key_buffer_size=4G
sort_buffer_size=4M
read_buffer_size=2M
read_rnd_buffer_size=2M
thread_cache_size=128
innodb_buffer_pool_size=32G
innodb_thread_concurrency=48
innodb_log_file_size=250M
innodb_log_buffer_size=8M
innodb_file_per_table=1
innodb_lock_wait_timeout=500
innodb_flush_method=O_DIRECT
tmp_table_size=256M
max_heap_table_size=256M
character-set-server=latin1
collation-server=latin1_danish_ci
slow_query_log=1
sql_mode=''