Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 20940 invoked from network); 13 Sep 2002 08:18:07 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 13 Sep 2002 08:18:07 -0000 Received: (qmail 2700 invoked by uid 97); 13 Sep 2002 08:18:51 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 2638 invoked by uid 97); 13 Sep 2002 08:18:50 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 2611 invoked by uid 50); 13 Sep 2002 08:18:49 -0000 Date: 13 Sep 2002 08:18:49 -0000 Message-ID: <20020913081849.2586.qmail@nagoya.betaversion.org> From: bugzilla@apache.org To: commons-dev@jakarta.apache.org Cc: Subject: DO NOT REPLY [Bug 12607] New: - ChunkedInputStream broken (2 bugs + fixes, 1 suggestion) X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT . ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE. http://nagoya.apache.org/bugzilla/show_bug.cgi?id=12607 ChunkedInputStream broken (2 bugs + fixes, 1 suggestion) Summary: ChunkedInputStream broken (2 bugs + fixes, 1 suggestion) Product: Commons Version: Nightly Builds Platform: PC OS/Version: Windows NT/2K Status: NEW Severity: Major Priority: Other Component: HttpClient AssignedTo: commons-dev@jakarta.apache.org ReportedBy: erik.van-der-goot@jrc.it Bug 1. In the read(byte[] b, int off, int len) method of ChunkedInputStream, the number of bytes to read from the underlying InputStream is calculated wrongly. In the code this is done by len = Math.min(len, chunkSize); This could (and will) cause the server (also Apache) to indeed serve that number of bytes (let's say chunkSize), but it may be that we already had a number of bytes on the first read. The result is that the input is now NOT positioned on the end of a chunk and the rest of the reader fails because it cannot find CRLF or a valid chunksize. Proposed fix (works, tested) len = Math.min(len, chunkSize-pos); Bug 2. In the calculation of the chunkSize (method getChunkSizeFromInputStream) the conversion to int is done by calling result = Integer.parseInt(dataString, 16); This is not robust and causes the occasional crash. The fix is simple and in fact implements what is done when the chunkSize is commented (see lines in code above) result = Integer.parseInt(dataString.trim(), 16); Tested and works. Suggestion: Same routine, input state machine. Perhaps just being pedantic..change while loop to: while (state != 2) { int b = in.read(); if (b == -1) throw new IOException("chunked stream ended unexpectedly"); switch (state) { case 0: if (b == '\r') state = 1; else baos.write(b); break; case 1: if (b == '\n') state = 2; else{ // this was not CRLF, so now write '\r' + this char baos.write('\r'); baos.write(b); state = 0; } break; default: throw new RuntimeException("assertion failed"); } } -- To unsubscribe, e-mail: For additional commands, e-mail: