Index: connectors/util/java/org/apache/tomcat/util/buf/CharChunk.java =================================================================== --- connectors/util/java/org/apache/tomcat/util/buf/CharChunk.java (Revision 648322) +++ connectors/util/java/org/apache/tomcat/util/buf/CharChunk.java (Arbeitskopie) @@ -478,7 +478,7 @@ tmp=new char[newSize]; } - System.arraycopy(buff, start, tmp, start, end-start); + System.arraycopy(buff, 0, tmp, 0, end); buff = tmp; tmp = null; } Index: connectors/util/java/org/apache/tomcat/util/buf/B2CConverter.java =================================================================== --- connectors/util/java/org/apache/tomcat/util/buf/B2CConverter.java (Revision 648322) +++ connectors/util/java/org/apache/tomcat/util/buf/B2CConverter.java (Arbeitskopie) @@ -82,17 +82,12 @@ { // Set the ByteChunk as input to the Intermediate reader iis.setByteChunk( bb ); - convert(cb, limit); - } - - private void convert(CharChunk cb, int limit) - throws IOException - { try { // read from the reader - int count = 0; + int bbLengthBeforeRead = 0; while( limit > 0 ) { int size = limit < BUFFER_SIZE ? limit : BUFFER_SIZE; + bbLengthBeforeRead = bb.getLength(); int cnt=conv.read( result, 0, size ); if( cnt <= 0 ) { // End of stream ! - we may be in a bad state @@ -106,7 +101,7 @@ // XXX go directly cb.append( result, 0, cnt ); - limit -= cnt; + limit = limit - (bbLengthBeforeRead - bb.getLength()); } } catch( IOException ex) { if( debug>0) @@ -222,6 +217,14 @@ /** Reset the buffer */ public final void recycle() { + try { + // Must clear super's buffer. + while (ready()) { + // InputStreamReader#skip(long) will allocate buffer to skip. + read(); + } + } catch(IOException ioe){ + } } }