Bug 49398

Summary: ByteChunk.indexOf(String, ...) behaviour with strings of length 1
Product: Tomcat 6 Reporter: Konstantin Kolinko <knst.kolinko>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: minor    
Priority: P2    
Version: 6.0.26   
Target Milestone: default   
Hardware: PC   
OS: Windows XP   

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.