Description:
There's a simple, but effective bug in the function
final String readString(String encoding) throws SQLException
of class
com.mysql.jdbc.Buffer
The function will not return the correct buffer content, but a string behind(!) the end_of_content pointer. That area is filled with random stuff from prior usages of that buffer.
You can easily see the bug if you compare this function to function
final String readString() throws SQLException
(without parameter) of the same class, because that function is correct.
How to repeat:
I wonder how this bug i still alive. Maybe it's due to the fact, that it only occours, if i do an
LOAD DATA LOCAL INFILE <filename> INTO TABLE <tablename>
But this bug is trivial, so look at the suggested fix. It's self explanatory.
Suggested fix:
*** mysql-connector-java-3.0.15-ga/com/mysql/jdbc/Buffer.java Sat Sep 4 02:14:52 2004
--- mysql-connector-java-3.0.15-ga-fixed/com/mysql/jdbc/Buffer.java Thu Oct 21 16:21:45 2004
***************
*** 370,383 ****
i++;
}
! this.position += (len + 1); // update cursor
try {
! return new String(this.byteBuffer, this.position, len, encoding);
} catch (UnsupportedEncodingException uEE) {
throw new SQLException("Unsupported character encoding '" + encoding + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
}
final int readnBytes() {
--- 370,390 ----
i++;
}
!
! String tmp;
try {
! tmp = new String(this.byteBuffer, this.position, len, encoding);
} catch (UnsupportedEncodingException uEE) {
throw new SQLException("Unsupported character encoding '" + encoding + "'", SQLError.SQL_STATE_ILLEGAL_ARGUMENT);
}
+ finally
+ {
+ this.position += (len + 1); // update cursor. *hgmoll* That has to be done AFTER creating the String object as it is done in readString()
+ }
+
+ return tmp;
}
final int readnBytes() {