[CONJ-805] >1Byte UTF8 character issue if maxFieldSize is set Created: 2020-07-02  Updated: 2020-09-10  Resolved: 2020-09-10

Status: Closed
Project: MariaDB Connector/J
Component/s: JDBC 4.2 compatibility
Affects Version/s: 2.6.1
Fix Version/s: 2.7.0

Type: Bug Priority: Critical
Reporter: Markus Lutum Assignee: Diego Dupin
Resolution: Fixed Votes: 0
Labels: None


 Description   

Detected at one of my clients.
They use polish special characters like ść
The length in TextRowProtocol is set to 2 for each of those characters so 4 in our example.
With this the current code

return new String(buf, pos, Math.min(maxFieldSize * 3, length), StandardCharsets.UTF_8) .substring(0, Math.min(maxFieldSize, length));

results into an ArrayOutOfBoundsError at the substring() call.

I added a test case and a quick fix for it.
See
https://github.com/mariadb-corporation/mariadb-connector-j/pull/156

Travis fails on environment issues. Nothing to do with my change. I can not rerun them....



 Comments   
Comment by Diego Dupin [ 2020-09-10 ]

The correction has 2 results :

  • Correction of possible ArrayOutOfBoundsError when using setMaxFieldSize
  • Correct behavior of setMaxFieldSize, limiting not length of the string, but byte length, as spec indicate :

    8.3.1 Silent Truncation. The Statement.setMaxFieldSize method allows a maximum size (in bytes) to be set. This limit applies only to the BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR, LONGVARCHAR, NCHAR, NVARCHAR, and LONGNVARCHAR data types. If a limit has been set using setMaxFieldSize and there is an attempt to read data that exceeds the limit, any truncation that occurs as a result of exceeding the set limit will not be reported.

Generated at Thu Feb 08 03:18:26 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.