Index: src/test/unit/org/jboss/seam/test/unit/testng.xml
===================================================================
--- src/test/unit/org/jboss/seam/test/unit/testng.xml	(revision 14145)
+++ src/test/unit/org/jboss/seam/test/unit/testng.xml	(revision 14146)
@@ -64,6 +64,7 @@
    <test name="Seam Unit Tests - Filters">
      <classes>
         <class name="org.jboss.seam.test.unit.web.MultipartRequestTest" />
+        <class name="org.jboss.seam.test.unit.web.MultipartRequestImplTest" />
         <class name="org.jboss.seam.test.unit.web.IdentityRequestWrapperTest" />
      </classes>
    </test>
Index: src/test/unit/org/jboss/seam/test/unit/web/MultipartRequestImplTest.java
===================================================================
--- src/test/unit/org/jboss/seam/test/unit/web/MultipartRequestImplTest.java	(revision 0)
+++ src/test/unit/org/jboss/seam/test/unit/web/MultipartRequestImplTest.java	(revision 14146)
@@ -0,0 +1,91 @@
+package org.jboss.seam.test.unit.web;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Map;
+import org.testng.annotations.Test;
+import org.jboss.seam.web.MultipartRequestImpl;
+import org.jboss.seam.mock.EnhancedMockHttpServletRequest;
+
+public class MultipartRequestImplTest
+{
+   private static final String CRLF = "\r\n";
+   private static final String HYPHENS = "--";
+
+   @Test
+   public void testParseRequestBasic() throws Throwable
+   {
+      String boundary = "boundary10"; //10 bytes
+
+      String data =
+         HYPHENS + boundary + CRLF +
+         "Content-Disposition: form-data; name=\"foo\"" + CRLF +
+         CRLF +
+         "bar" + CRLF +
+         HYPHENS + boundary + HYPHENS;
+          
+      byte[] dataBytes = data.getBytes("UTF-8");
+
+      EnhancedMockHttpServletRequest req = new EnhancedMockHttpServletRequest();
+      req.setContent(dataBytes);
+      req.setContentType("multipart/form-data; boundary=" + boundary);
+      MultipartRequestImpl r = new MultipartRequestImpl(req, false, 0);
+      Map m = r.getParameterMap();
+      assertNotNull(m);
+      assertEquals(r.getParameterValues("foo")[0], "bar");
+   }
+
+   @Test
+   public void testParseRequestBufferBoundary() throws Throwable
+   {
+
+      int bufferSize = 2048; // See MultipartRequestImpl
+
+      String boundary = "boundary10";
+
+      String paddingParameter =
+         HYPHENS + boundary + CRLF +
+         "Content-Disposition: form-data; name=\"padding\"" + CRLF +
+         CRLF;
+
+      String testParameter =
+         HYPHENS + boundary + CRLF +
+         "Content-Disposition: form-data; name=\"foo\"" + CRLF +
+         CRLF +
+         "bar" + CRLF +
+         HYPHENS + boundary + HYPHENS;
+
+      // let's put test parameter near the buffer boundary, from (bufferSize - 100) to (bufferSize + 100)
+      for (int i = -100; i < 100; i++)
+      {
+         StringBuffer buffer = new StringBuffer(bufferSize + 256);
+         buffer.append(paddingParameter);
+         int paddingSize = bufferSize - i - paddingParameter.length() - CRLF.length();
+         appendPaddingValue(buffer, paddingSize);
+         buffer.append(CRLF);
+         buffer.append(testParameter);
+         String data = buffer.toString();
+
+         byte[] dataBytes = data.getBytes("UTF-8");
+         EnhancedMockHttpServletRequest req = new EnhancedMockHttpServletRequest();
+         req.setContent(dataBytes);
+         req.setContentType("multipart/form-data; boundary=" + boundary);
+         MultipartRequestImpl r = new MultipartRequestImpl(req, false, 0);
+         Map m = r.getParameterMap();
+         assertNotNull(m);
+         assertEquals(r.getParameterValues("foo")[0], "bar");
+      }
+   }
+
+   private static StringBuffer appendPaddingValue(StringBuffer buffer, int length)
+   {
+      for (int i = 0; i < length; i++)
+      {
+         buffer.append("x");
+      }
+      return buffer;
+   }
+}
Index: src/main/org/jboss/seam/web/MultipartRequestImpl.java
===================================================================
--- src/main/org/jboss/seam/web/MultipartRequestImpl.java	(revision 14145)
+++ src/main/org/jboss/seam/web/MultipartRequestImpl.java	(revision 14146)
@@ -330,6 +330,14 @@
                   {
                      if (checkSequence(buffer, i, CR_LF))
                      {
+                        // Check next CR_LF available in the buffer
+                        if ( read <= i + CR_LF.length)
+                        {  /* if there is no space left for CRLF in the buffer, 
+                           force pushing of remaining (unread) bytes to the beginning of the buffer,
+                           read more bytes and try again */
+                           i = read;
+                           break;
+                        }
                         String param = (encoding == null) ? 
                                  new String(buffer, pos, i - pos - 1) :
                                  new String(buffer, pos, i - pos - 1, encoding);                        
@@ -420,16 +428,40 @@
             {
                // move the bytes that weren't read to the start of the buffer
                int bytesNotRead = read - pos;
-               System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);               
-               read = input.read(buffer, bytesNotRead, buffer.length - bytesNotRead);
                
-               // Decrement loopCounter if no data was readable
-               if (read == 0)
+               if (buffer.length == bytesNotRead ) 
                {
-                  loopCounter--;
-               }
+                  //if no end of parameter value can be found in the buffer, we have to increase size of the buffer                                    
+                  
+                  byte[] buffer1 = new byte[buffer.length * 2];
+                  System.arraycopy(buffer, 0, buffer1, 0, buffer.length);
+                  buffer = buffer1;
+                  
+                  read = input.read(buffer, bytesNotRead, buffer.length - bytesNotRead);
+                  if (read == -1) 
+                  {
+                     break;// too bad - nothing more to read (EOF) and last parameter value couldn't be parsed
+                  }
+          
+                  read += bytesNotRead;
+                  } 
+                  else 
+                  {
+                     System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);
+                     read = input.read(buffer, bytesNotRead, buffer.length - bytesNotRead);
+                  
+                     if (read == -1) 
+                     {
+                        break;
+                        // too bad - nothing more to read (EOF) and last parameter value couldn't be parsed
+                     }
+                     
+                     if(read == 0)
+                        loopCounter--;
+                     
+                     read += bytesNotRead;
+                  }
                
-               read += bytesNotRead;
             }
             else
             {
