james-mime4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1138335 - in /james/mime4j/trunk/core/src: main/java/org/apache/james/mime4j/io/ test/java/org/apache/james/mime4j/io/ test/resources/testmsgs/
Date Wed, 22 Jun 2011 08:34:42 GMT
Author: olegk
Date: Wed Jun 22 08:34:41 2011
New Revision: 1138335

URL: http://svn.apache.org/viewvc?rev=1138335&view=rev
Log:
MIME4J-199: boundary scanning code in MimeBoundaryInputStream improved; extra check added
to ensure that multipart boundary is properly terminated with a whitedspace or '-' char

Added:
    james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.msg   (with
props)
    james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.out   (with
props)
    james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.xml   (with
props)
    james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded.xml
  (with props)
    james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_1.txt
  (with props)
    james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_2.txt
  (with props)
    james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_2.txt
  (with props)
Modified:
    james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
    james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java

Modified: james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java?rev=1138335&r1=1138334&r2=1138335&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
(original)
+++ james/mime4j/trunk/core/src/main/java/org/apache/james/mime4j/io/MimeBoundaryInputStream.java
Wed Jun 22 08:34:41 2011
@@ -22,6 +22,7 @@ package org.apache.james.mime4j.io;
 import org.apache.james.mime4j.MimeException;
 import org.apache.james.mime4j.MimeIOException;
 import org.apache.james.mime4j.util.ByteArrayBuffer;
+import org.apache.james.mime4j.util.CharsetUtil;
 
 import java.io.IOException;
 
@@ -227,15 +228,30 @@ public class MimeBoundaryInputStream ext
             bytesRead = 0;
         }
         
-        
-        int i = buffer.indexOf(boundary);
-        // NOTE this currently check only for LF. It doesn't check for canonical CRLF
-        // and neither for isolated CR. This will require updates according to MIME4J-60
-        while (i > buffer.pos() && buffer.byteAt(i-1) != '\n') {
-            // skip the "fake" boundary (it does not contain LF or CR so we cannot have
-            // another boundary starting before this is complete.
-            i = i + boundary.length;
-            i = buffer.indexOf(boundary, i, buffer.limit() - i);
+        int i;
+        int off = buffer.pos();
+        for (;;) {
+            i = buffer.indexOf(boundary, off, buffer.limit() - off);
+            if (i == -1) {
+                break;
+            }
+            // Make sure the boundary is either at the very beginning of the buffer 
+            // or preceded with LF
+            if (i == buffer.pos() || buffer.byteAt(i - 1) == '\n') {
+                int pos = i + boundary.length;
+                int remaining = buffer.limit() - pos;
+                if (remaining <= 0) {
+                    // Make sure the boundary is terminated with EOS
+                    break;
+                } else {
+                    // or with a whitespace or '-' char
+                    char ch = (char)(buffer.byteAt(pos));
+                    if (CharsetUtil.isWhitespace(ch) || ch == '-') {
+                        break;
+                    }
+                }
+            }
+            off = i + boundary.length;
         }
         if (i != -1) {
             limit = i;
@@ -245,8 +261,8 @@ public class MimeBoundaryInputStream ext
             if (eof) {
                 limit = buffer.limit();
             } else {
-                limit = buffer.limit() - (boundary.length + 1); 
-                                          // \r\n + (boundary - one char)
+                limit = buffer.limit() - (boundary.length + 2); 
+                                // [LF] [boundary] [CR][LF] minus one char 
             }
         }
         return bytesRead;

Modified: james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java?rev=1138335&r1=1138334&r2=1138335&view=diff
==============================================================================
--- james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java
(original)
+++ james/mime4j/trunk/core/src/test/java/org/apache/james/mime4j/io/MimeBoundaryInputStreamTest.java
Wed Jun 22 08:34:41 2011
@@ -218,7 +218,7 @@ public class MimeBoundaryInputStreamTest
      * Tests that a stream containing only a boundary is empty.
      */
     public void testPrefixIsBoundary() throws IOException {
-        String text = "Line 1\r\n\r\n--boundaryyada\r\n";
+        String text = "Line 1\r\n\r\n--boundary\r\n";
         
         ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes());
         BufferedLineReaderInputStream buffer = new BufferedLineReaderInputStream(bis, 4096);

@@ -226,7 +226,7 @@ public class MimeBoundaryInputStreamTest
             new MimeBoundaryInputStream(buffer, "boundary");
         assertEquals("Line 1\r\n", read(stream, 100));
         
-        text = "--boundaryyada\r\n";
+        text = "--boundary\r\n";
         
         bis = new ByteArrayInputStream(text.getBytes());
         buffer = new BufferedLineReaderInputStream(bis, 4096); 

Added: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.msg
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.msg?rev=1138335&view=auto
==============================================================================
Binary file - no diff available.

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.msg
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.out
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.out?rev=1138335&view=auto
==============================================================================
Binary file - no diff available.

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.out
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.xml?rev=1138335&view=auto
==============================================================================
Binary file - no diff available.

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries.xml
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded.xml
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded.xml?rev=1138335&view=auto
==============================================================================
Binary file - no diff available.

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded.xml
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded.xml
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_1.txt
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_1.txt?rev=1138335&view=auto
==============================================================================
Binary file - no diff available.

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_1.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_1.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_1.txt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_2.txt
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_2.txt?rev=1138335&view=auto
==============================================================================
Binary file - no diff available.

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_2.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_2.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_1_2.txt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_2.txt
URL: http://svn.apache.org/viewvc/james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_2.txt?rev=1138335&view=auto
==============================================================================
Binary file - no diff available.

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_2.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_2.txt
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: james/mime4j/trunk/core/src/test/resources/testmsgs/overlapping-boundaries_decoded_1_2.txt
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message