Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 34923 invoked from network); 15 Oct 2010 19:03:43 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Oct 2010 19:03:43 -0000 Received: (qmail 6199 invoked by uid 500); 15 Oct 2010 19:03:43 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 6093 invoked by uid 500); 15 Oct 2010 19:03:43 -0000 Mailing-List: contact commits-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 commits@cxf.apache.org Received: (qmail 6086 invoked by uid 99); 15 Oct 2010 19:03:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Oct 2010 19:03: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.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 15 Oct 2010 19:03:40 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 81CA723889E0; Fri, 15 Oct 2010 19:02:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1023071 - in /cxf/branches/2.2.x-fixes: ./ common/common/src/main/java/org/apache/cxf/helpers/ rt/core/src/main/java/org/apache/cxf/attachment/ rt/core/src/test/java/org/apache/cxf/attachment/ Date: Fri, 15 Oct 2010 19:02:43 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101015190243.81CA723889E0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Fri Oct 15 19:02:43 2010 New Revision: 1023071 URL: http://svn.apache.org/viewvc?rev=1023071&view=rev Log: Merged revisions 1023069 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.3.x-fixes ................ r1023069 | dkulp | 2010-10-15 14:55:00 -0400 (Fri, 15 Oct 2010) | 9 lines Merged revisions 1023068 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1023068 | dkulp | 2010-10-15 14:53:40 -0400 (Fri, 15 Oct 2010) | 1 line [CXF-3068] Make sure the streams don't return 0 for anything. ........ ................ Modified: cxf/branches/2.2.x-fixes/ (props changed) cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Propchange: cxf/branches/2.2.x-fixes/ ('svn:mergeinfo' removed) Propchange: cxf/branches/2.2.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java?rev=1023071&r1=1023070&r2=1023071&view=diff ============================================================================== --- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java (original) +++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/IOUtils.java Fri Oct 15 19:02:43 2010 @@ -134,6 +134,9 @@ public final class IOUtils { n = input.read(buffer); int total = 0; while (-1 != n) { + if (n == 0) { + throw new IOException("0 bytes read in violation of InputStream.read(byte[])"); + } output.write(buffer, 0, n); total += n; n = input.read(buffer); @@ -147,6 +150,9 @@ public final class IOUtils { int n = 0; n = input.read(buffer); while (-1 != n) { + if (n == 0) { + throw new IOException("0 bytes read in violation of InputStream.read(byte[])"); + } output.write(buffer, 0, n); n = input.read(buffer); } @@ -169,6 +175,9 @@ public final class IOUtils { int n = 0; n = input.read(buffer); while (-1 != n) { + if (n == 0) { + throw new IOException("0 bytes read in violation of InputStream.read(byte[])"); + } buf.append(newStringFromBytes(buffer, 0, n)); n = input.read(buffer); } @@ -183,6 +192,9 @@ public final class IOUtils { int n = 0; n = input.read(buffer); while (-1 != n) { + if (n == 0) { + throw new IOException("0 bytes read in violation of InputStream.read(byte[])"); + } buf.append(new String(buffer, 0, n)); n = input.read(buffer); } Modified: cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java?rev=1023071&r1=1023070&r2=1023071&view=diff ============================================================================== --- cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java (original) +++ cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java Fri Oct 15 19:02:43 2010 @@ -70,9 +70,20 @@ public class MimeBodyPartInputStream ext if (len > pbAmount) { len = pbAmount; //can only pushback that much so make sure we can } - if (len > 0) { - len = inStream.read(b, off, len); + int read = 0; + int idx = 0; + while (read >= 0 && idx < len && idx < (boundary.length * 2)) { + //make sure we read enough to detect the boundary + read = inStream.read(b, off + idx, len - idx); + if (read != -1) { + idx += read; + } + } + if (read == -1 && idx == 0) { + return -1; } + len = idx; + int i = processBuffer(b, off, len); if (bufferCreated && i > 0) { // read more than we need, push it back @@ -86,6 +97,7 @@ public class MimeBodyPartInputStream ext } else if (i == 0 && boundaryFound) { return -1; } + return i; } Modified: cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=1023071&r1=1023070&r2=1023071&view=diff ============================================================================== --- cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java (original) +++ cxf/branches/2.2.x-fixes/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java Fri Oct 15 19:02:43 2010 @@ -20,6 +20,7 @@ package org.apache.cxf.attachment; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; import java.util.Collection; @@ -396,5 +397,64 @@ public class AttachmentDeserializerTest message.getAttachments().size(); } + @Test + public void testDoesntReturnZero() throws Exception { + String contentType = "multipart/mixed;boundary=----=_Part_1"; + byte[] messageBytes = ( + "------=_Part_1\n\n" + + "JJJJ\n" + + "------=_Part_1" + + "\n\nContent-Transfer-Encoding: binary\n\n" + + "ABCD1\r\n" + + "------=_Part_1" + + "\n\nContent-Transfer-Encoding: binary\n\n" + + "ABCD2\r\n" + + "------=_Part_1" + + "\n\nContent-Transfer-Encoding: binary\n\n" + + "ABCD3\r\n" + + "------=_Part_1--").getBytes("UTF-8"); + ByteArrayInputStream in = new ByteArrayInputStream(messageBytes) { + public int read(byte[] b, int off, int len) { + return super.read(b, off, len >= 2 ? 2 : len); + } + }; + + Message message = new MessageImpl(); + message.put(Message.CONTENT_TYPE, contentType); + message.setContent(InputStream.class, in); + message.put(AttachmentDeserializer.ATTACHMENT_DIRECTORY, System + .getProperty("java.io.tmpdir")); + message.put(AttachmentDeserializer.ATTACHMENT_MEMORY_THRESHOLD, String + .valueOf(AttachmentDeserializer.THRESHOLD)); + + + AttachmentDeserializer ad + = new AttachmentDeserializer(message, + Collections.singletonList("multipart/mixed")); + + ad.initializeAttachments(); + + String s = getString(message.getContent(InputStream.class)); + assertEquals("JJJJ", s.trim()); + int count = 1; + for (Attachment a : message.getAttachments()) { + s = getString(a.getDataHandler().getInputStream()); + assertEquals("ABCD" + count++, s); + } + } + + private String getString(InputStream ins) throws Exception { + ByteArrayOutputStream bout = new ByteArrayOutputStream(100); + byte b[] = new byte[100]; + int i = ins.read(b); + while (i > 0) { + bout.write(b, 0 , i); + i = ins.read(b); + } + if (i == 0) { + throw new IOException("Should not be 0"); + } + return bout.toString(); + } } \ No newline at end of file