cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r921945 - in /cxf/trunk/rt/core/src: main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Date Thu, 11 Mar 2010 17:11:57 GMT
Author: dkulp
Date: Thu Mar 11 17:11:57 2010
New Revision: 921945

URL: http://svn.apache.org/viewvc?rev=921945&view=rev
Log:
[CXF-2706] Fix issues with missing ending boundary causing a loop

Modified:
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java
    cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java?rev=921945&r1=921944&r2=921945&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/attachment/MimeBodyPartInputStream.java
Thu Mar 11 17:11:57 2010
@@ -94,9 +94,17 @@ public class MimeBodyPartInputStream ext
         throws IOException {
         if (pointer < (off + len)) {
             return true;
-        } else {
+        } else if (pointer >= 1000000000) {
             inStream.unread(b, initialPointer, (off + len) - initialPointer);
-            return false;
+            return false;            
+        } else {
+            int x = inStream.read();
+            if (x != -1) {
+                inStream.unread(x);
+                inStream.unread(b, initialPointer, (off + len) - initialPointer);
+                return false;
+            }
+            return true;
         }
     }
 

Modified: cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java?rev=921945&r1=921944&r2=921945&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
(original)
+++ cxf/trunk/rt/core/src/test/java/org/apache/cxf/attachment/AttachmentDeserializerTest.java
Thu Mar 11 17:11:57 2010
@@ -23,6 +23,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.io.PushbackInputStream;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -38,6 +39,8 @@ import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.message.XMLMessage;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -365,4 +368,33 @@ public class AttachmentDeserializerTest 
         SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
         parser.parse(inputStreamWithoutAttachments, new DefaultHandler());
     }
+    
+    @Test
+    public void imitateAttachmentInInterceptorForMessageWithMissingBoundary() throws Exception
{
+        ByteArrayInputStream inputStream;
+        String contentType = "multipart/mixed;boundary=abc123";
+        String data = "--abc123\r\n\r\n<Document></Document>\r\n\r\n";
+
+        Message message;
+
+        inputStream = new ByteArrayInputStream(data.getBytes());
+
+        message = new XMLMessage(new MessageImpl());
+        message.put(Message.CONTENT_TYPE, contentType);
+        message.setContent(InputStream.class, inputStream);
+        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();
+        message.getAttachments().size();
+
+    }
+
 }
\ No newline at end of file



Mime
View raw message