[MDEV-32975] Default charset doesn't work with PHP MySQLi extension Created: 2023-12-08 Updated: 2024-01-26 |
|
| Status: | In Review |
| Project: | MariaDB Server |
| Component/s: | Character Sets |
| Affects Version/s: | 11.3.1 |
| Fix Version/s: | 10.4, 10.5, 10.6, 10.11, 11.0, 11.1, 11.2 |
| Type: | Bug | Priority: | Critical |
| Reporter: | David Warner | Assignee: | Sergei Golubchik |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Ubuntu 22.04 LTS |
||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
Some charset change in MariaDB 11.3.1 appears to break PHP clients, raising the error 'Server sent charset (0) unknown to the client'. I noticed /etc/mysql/mariadb.conf.d/50-server.cnf changed If I change this back, connections from PHP work again. This Plesk user seems to have encountered the same issue: https://talk.plesk.com/threads/500-plesk-exception-database-db-query-failed-sqlstate-hy000-2054-server-sent-charset-0-unknown-to-the-client.372563/ Steps to reproduce:
|
| Comments |
| Comment by Sergei Golubchik [ 2023-12-11 ] | |||||||||||||||||||||||||
|
it's coming from https://github.com/php/php-src/blob/642e11140c3a8461ab9a78d6ce3d3a79b0151987/ext/mysqlnd/mysqlnd_commands.c#L619 and the reason is that the server sends 0 in the server default collation byte of the initial handshake packet for collations that are above 1..255 range. But actually the connector is mainly interested in the character set, not the collation. We could try to "gracefully downgrade" the collation and if it's above 255, return another collation of the same character set but with a smaller id. | |||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2023-12-12 ] | |||||||||||||||||||||||||
|
There is a difference between how MySQL-4.0 worked comparing to MySQL-4.1 and all further MySQL and MariaDB releases:
We can gracefully downgrade the collation ID. But the real fix should also be done in the PHP connector - it should not read this collation ID at all. | |||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-12-12 ] | |||||||||||||||||||||||||
|
it seems that mysqlnd sets the desired character set if the client specified it, otherwise it sets the server charset from the initial handshake packet: https://github.com/php/php-src/blob/master/ext/mysqlnd/mysqlnd_auth.c#L285-L289 And if we do a graceful downgrade, we might get it back as the requested character_set_client. | |||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-12-12 ] | |||||||||||||||||||||||||
|
instead of "graceful downgrade" we can implement | |||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2024-01-26 ] | |||||||||||||||||||||||||
|
Reproduces as described. 1. Start the server as follows:
2. Run php with this program:
It produces the following output:
| |||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2024-01-26 ] | |||||||||||||||||||||||||
|
The problem with the fact that the collation ID is sent from the server to the client using one byte in the handshake packet is also repeatable with all version. I run a 10.4 server as follows:
then run the above PHP program. It produces the following output:
Notice, the connection character set was erroneously set to armscii8. The problem happens with all collations listed by this statement:
Instead of the true collation ID (displayed in the second column), the server only sends its lower 8 bits, which changes not only the collation, but also the character set for the listed collations. | |||||||||||||||||||||||||
| Comment by Alexander Barkov [ 2024-01-26 ] | |||||||||||||||||||||||||
|
Hello serg, Please review a patch: https://github.com/MariaDB/server/commit/7ff9e91a7d2872881526ff80366bf4857be61414 Thanks. | |||||||||||||||||||||||||
| Comment by David Warner [ 2024-01-26 ] | |||||||||||||||||||||||||
|
Thanks for looking into this. Is it feasible to add integration tests for popular connectors to catch issues like this in the future? | |||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2024-01-26 ] | |||||||||||||||||||||||||
|
We have some, builders at buildbot.mariadb.org with the "eco" in the name:
but they aren't enforced yet, still work in progress. |