Bug 49398 - ByteChunk.indexOf(String, ...) behaviour with strings of length 1
Summary: ByteChunk.indexOf(String, ...) behaviour with strings of length 1
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 6
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 6.0.26
Hardware: PC Windows XP
: P2 minor (vote)
Target Milestone: default
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-07 11:21 UTC by Konstantin Kolinko
Modified: 2010-06-07 11:42 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Kolinko 2010-06-07 11:21:58 UTC
There is a bug in implementation of the following method
org.apache.tomcat.util.buf.ByteChunk.indexOf(String src, int srcOff, int srcLen, int myOff) in 6.0.26 and 5.5.29.

The problem is that the method can not find a string which consists of one character, as the only successful exit from the method is from inside the loop that checks the second and subsequent characters.

E.g., to reproduce:
byte[] bytes = "Hello\u00a0world".getBytes("ISO-8859-1");
final int len = bytes.length;
ByteChunk bc = new ByteChunk();
bc.setBytes(bytes, 0, len);
bc.indexOf("o", 0, 1, 5); // returns -1, instead of 7.

A testcase for this was added in r945230 and it was fixed in trunk in r945231

This is not observable without a testcase, because all calls to this method in the current Tomcat 6.0.26 and 5.5.29 code pass a string of several characters.
Comment 1 Konstantin Kolinko 2010-06-07 11:42:15 UTC
Fixed in 5.5 and 6.0, will be in 5.5.30, 6.0.27.