Description:
The JDBC driver throws an ArrayIndexOutOfBoundsException when
PreparedStatement.setString() is called with a String containing Unicode char 0xFFFF.
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 65535
at
com.mysql.jdbc.SingleByteCharsetConverter.toBytes(SingleByteCharsetConverter.java:160)
at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:88)
at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:1053)
at Arr.main(Arr.java:9)
This happens with Connector/J 3.0.6 and 3.0.7
How to repeat:
Run this sample program, changing the connection URL/login info:
import java.sql.*;
public class Arr {
public static void main(String args[]) throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://XXXX:3306/XXX", "XXX",
"XXX");
PreparedStatement stmt = con.prepareStatement("SELECT ?");
stmt.setString(1, "hello \uFFFF");
}
}
Suggested fix:
The private arrays charToByteMap and unknownCharsMap in
com.mysql.jdbc.SingleByteCharsetConverter need to be declared with 65536 bytes:
line 40:
private static byte[] unknownCharsMap = new byte[65536];
line 56:
private byte[] charToByteMap = new byte[65536];
Description: The JDBC driver throws an ArrayIndexOutOfBoundsException when PreparedStatement.setString() is called with a String containing Unicode char 0xFFFF. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 65535 at com.mysql.jdbc.SingleByteCharsetConverter.toBytes(SingleByteCharsetConverter.java:160) at com.mysql.jdbc.StringUtils.getBytes(StringUtils.java:88) at com.mysql.jdbc.PreparedStatement.setString(PreparedStatement.java:1053) at Arr.main(Arr.java:9) This happens with Connector/J 3.0.6 and 3.0.7 How to repeat: Run this sample program, changing the connection URL/login info: import java.sql.*; public class Arr { public static void main(String args[]) throws Exception { Class.forName("com.mysql.jdbc.Driver"); Connection con = DriverManager.getConnection("jdbc:mysql://XXXX:3306/XXX", "XXX", "XXX"); PreparedStatement stmt = con.prepareStatement("SELECT ?"); stmt.setString(1, "hello \uFFFF"); } } Suggested fix: The private arrays charToByteMap and unknownCharsMap in com.mysql.jdbc.SingleByteCharsetConverter need to be declared with 65536 bytes: line 40: private static byte[] unknownCharsMap = new byte[65536]; line 56: private byte[] charToByteMap = new byte[65536];