Return-Path: Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: (qmail 81187 invoked from network); 21 Oct 2010 20:36:44 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 Oct 2010 20:36:44 -0000 Received: (qmail 98681 invoked by uid 500); 21 Oct 2010 20:36:44 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 98666 invoked by uid 500); 21 Oct 2010 20:36:44 -0000 Mailing-List: contact issues-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list issues@cxf.apache.org Received: (qmail 98657 invoked by uid 99); 21 Oct 2010 20:36:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Oct 2010 20:36:43 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Oct 2010 20:36:41 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o9LKaJZe022457 for ; Thu, 21 Oct 2010 20:36:19 GMT Message-ID: <27326416.15761287693379661.JavaMail.jira@thor> Date: Thu, 21 Oct 2010 16:36:19 -0400 (EDT) From: "aaron pieper (JIRA)" To: issues@cxf.apache.org Subject: [jira] Commented: (CXF-3068) MimeBodyPartInputStream illegally returns "0" from a read call with chunked InputStream In-Reply-To: <4488487.162901287154653504.JavaMail.jira@thor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CXF-3068?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12923618#action_12923618 ] aaron pieper commented on CXF-3068: ----------------------------------- Thanks Daniel - this fix works great! > MimeBodyPartInputStream illegally returns "0" from a read call with chunked InputStream > --------------------------------------------------------------------------------------- > > Key: CXF-3068 > URL: https://issues.apache.org/jira/browse/CXF-3068 > Project: CXF > Issue Type: Bug > Components: Core > Affects Versions: 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.2.7, 2.2.8, 2.2.9, 2.2.10 > Environment: Windows > Reporter: aaron pieper > Assignee: Daniel Kulp > Fix For: 2.2.12, 2.3.1 > > Attachments: cxf-3068-kludge-patch.txt, MimeBodyPartInputStreamTest.java > > > I'm having a problem with some MTOM attachments. It started when I upgraded from CXF 2.2.2 to CXF 2.2.3. The bug is that after calling a service which returned an MTOM attachment, when I try to parse the attachment, I sometimes get an error: > java.io.IOException: Underlying input stream returned zero bytes > at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:268) > at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) > at sun.nio.cs.StreamDecoder.READ(StreamDecoder.java:158) > at java.io.InputStreamReader.READ(InputStreamReader.java:167) > at java.io.Reader.READ(Reader.java:123) > at org.apache.commons.io.IOUtils.copyLarge(IOUtils.java:1128) > at org.apache.commons.io.IOUtils.copy(IOUtils.java:1104) > at org.apache.commons.io.IOUtils.copy(IOUtils.java:1050) > at org.apache.commons.io.IOUtils.toString(IOUtils.java:359) > at com.pragmatics.AsyncUtils.messageToString(AsyncUtils.java:18) > > The error only happens for some attachments - about 25% of them. It's a seemingly arbitrary 25% - it's not like, the biggest 25% or the ones that have special characters. I was able to track this down to MimeBodyPartInputStream. MimeBodypartInputStream has some logic in processBuffer for reading the boundary. It goes like this: > while ((boundaryIndex < boundary.length) && (value == boundary[boundaryIndex])) { if (!hasData(buffer, initialI, i + 1, off, len)) { > return initialI - off; > } > value = buffer[++i]; > boundaryIndex++; > } > So, basically, when MimeBodyPartInputStream finds the start of a boundary, it reads from the stream until either there's no more characters to read, or until it read the entire boundary. The problem with this logic is that it assumes the entire boundary will be read in the same call to the underlying InputStream. This assumption isn't always true. Specifically, when I'm fetching an attachment in my application, this MimeBodyPartInputStream is backed by an HttpURLConnection.HttpInputStream. This HttpInputStream sometimes fetches as few as 24 characters, I guess that's just how the HttpInputStream works. But if these 24 characters happen to fall on one of these MIME boundaries, it can cause problems. > One problem, which I'm running into here, is that the MimeBodyPartInputStream's read(byte,int,int) method returns 0, since the only bytes that were read were parts of the MIME boundary. In returning 0, it breaks InputStream's contract which says states that the read method will only ever return a positive integer (if some bytes were read) or -1 (if no bytes were read.) There are probably other possible problems - it seems like it's possible MimeBodyPartInputStream might misunderstand whether or not it's hit a boundary in some cases. I haven't run into that problem though. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.