Return-Path: X-Original-To: apmail-james-mime4j-dev-archive@minotaur.apache.org Delivered-To: apmail-james-mime4j-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C448A6596 for ; Wed, 22 Jun 2011 08:35:11 +0000 (UTC) Received: (qmail 22521 invoked by uid 500); 22 Jun 2011 08:35:11 -0000 Delivered-To: apmail-james-mime4j-dev-archive@james.apache.org Received: (qmail 22441 invoked by uid 500); 22 Jun 2011 08:35:07 -0000 Mailing-List: contact mime4j-dev-help@james.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: mime4j-dev@james.apache.org Delivered-To: mailing list mime4j-dev@james.apache.org Received: (qmail 22419 invoked by uid 99); 22 Jun 2011 08:35:04 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Jun 2011 08:35:04 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.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; Wed, 22 Jun 2011 08:35:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5AFC42388900; Wed, 22 Jun 2011 08:34:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: mime4j-dev@james.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110622083442.5AFC42388900@eris.apache.org> 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