Details
Description
The driver always encodes/decodes protocol text, and performs client-side escaping, assuming the session character set is UTF-8 (utf8mb3/utf8mb4).
The server character set can, however, be changed at runtime (e.g. the application issues SET NAMES latin1, SET character_set_client=…), and the server reports the new value back through session-state tracking, which the driver records.
Reported by fg0x0.
Fix: Once the connection is initialized, reject any server-reported character-set change to a value that isn't UTF-8 (only utf8 / utf8mb3 / utf8mb4 are allowed). On such a change the driver closes the connection and throws SQLNonTransientConnectionException (SQLState 08000), so no further statements can run against a session whose charset is out of sync with the driver's assumptions.