Bug #64731 | StringUtils.getBytesWrapped throws StringIndexOutOfBoundsException | ||
---|---|---|---|
Submitted: | 22 Mar 2012 7:01 | Modified: | 20 Jun 2012 21:46 |
Reporter: | zhang jinyan | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | 5.1.18 | OS: | Any |
Assigned to: | Alexander Soklakov | CPU Architecture: | Any |
Tags: | getBytesWrapped, StringIndexOutOfBoundsException, StringUtils |
[22 Mar 2012 7:01]
zhang jinyan
[22 Mar 2012 16:18]
zhang jinyan
Fix code should be: StringBuffer buf = new StringBuffer(s.length() + 2); buf.append(beginWrap); buf.append(s); buf.append(endWrap); s = buf.toString();// fix code b = s.getBytes(encoding);// fix code if (!parserKnowsUnicode && (encoding.equalsIgnoreCase("SJIS") //$NON-NLS-1$ || encoding.equalsIgnoreCase("BIG5") //$NON-NLS-1$ || encoding.equalsIgnoreCase("GBK"))) { //$NON-NLS-1$ if (!encoding.equalsIgnoreCase(serverEncoding)) { b = escapeEasternUnicodeByteStream(b, s, 0, s.length()); } }
[10 Apr 2012 8:22]
Alexander Soklakov
Verified as described.
[20 Jun 2012 21:46]
John Russell
Added to changelog for 5.1.21: With a connection encoding of gbk and a server encoding of latin1, a call such as PreparedStatement.setString(1, "0f0f0702") could thrown an exception java.lang.StringIndexOutOfBoundsException.