Author: markt
Date: Fri Feb 13 12:31:38 2015
New Revision: 1659537

URL: http://svn.apache.org/r1659537
Log:
Add support for maxSwallowSize

Modified:
    tomcat/tc6.0.x/trunk/STATUS.txt
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/Constants.java
    
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
    
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
    
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/LocalStrings.properties
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
    tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1659537&r1=1659536&r2=1659537&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Fri Feb 13 12:31:38 2015
@@ -34,11 +34,6 @@ PATCHES PROPOSED TO BACKPORT:
   +1: kkolinko, remm, markt
   -1:
 
-* Add support for maxSwallowSize to Tomcat 6
-  
http://people.apache.org/~markt/patches/2015-02-12-maxSwallowSize-tc6-v2.patch
-  +1: markt, kkolinko, remm
-  -1:
-
 * Backport some Jasper clean-up that might provide a marginal performance
   improvement. Even if it doesn't it removes some unnecessary code
   
http://people.apache.org/~markt/patches/2015-02-06-jasper-cleanup-tc6-v1.patch

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/Constants.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/Constants.java?rev=1659537&r1=1659536&r2=1659537&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/Constants.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/Constants.java Fri Feb 13 
12:31:38 2015
@@ -85,4 +85,13 @@ public final class Constants {
         Integer.parseInt(System.getProperty(
                 "org.apache.coyote.MAX_EXTENSION_SIZE",
                 "8192"));
+
+    /**
+     * Limit on the length of request body Tomcat will swallow if it is not
+     * read during normal request processing. Defaults to 2MB.
+     */
+    public static final int MAX_SWALLOW_SIZE =
+        Integer.parseInt(System.getProperty(
+                "org.apache.coyote.MAX_SWALLOW_SIZE",
+                "2097152"));
 }

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java?rev=1659537&r1=1659536&r2=1659537&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
 (original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/ChunkedInputFilter.java
 Fri Feb 13 12:31:38 2015
@@ -216,8 +216,15 @@ public class ChunkedInputFilter implemen
      * End the current request.
      */
     public long end() throws IOException {
+        int maxSwallowSize = org.apache.coyote.Constants.MAX_SWALLOW_SIZE;
+        long swallowed = 0;
+        int read = 0;
         // Consume extra bytes : parse the stream until the end chunk is found
-        while (doRead(readChunk, null) >= 0) {
+        while ((read = doRead(readChunk, null)) >= 0) {
+            swallowed += read;
+            if (maxSwallowSize > -1 && swallowed > maxSwallowSize) {
+                throwIOException(sm.getString("inputFilter.maxSwallow"));
+            }
         }
 
         // Return the number of extra bytes which were consumed

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java?rev=1659537&r1=1659536&r2=1659537&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
 (original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/IdentityInputFilter.java
 Fri Feb 13 12:31:38 2015
@@ -20,7 +20,7 @@ package org.apache.coyote.http11.filters
 import java.io.IOException;
 
 import org.apache.tomcat.util.buf.ByteChunk;
-
+import org.apache.tomcat.util.res.StringManager;
 import org.apache.coyote.InputBuffer;
 import org.apache.coyote.Request;
 import org.apache.coyote.http11.InputFilter;
@@ -32,9 +32,11 @@ import org.apache.coyote.http11.InputFil
  */
 public class IdentityInputFilter implements InputFilter {
 
+    private static final StringManager sm = StringManager.getManager(
+            IdentityInputFilter.class.getPackage().getName());
 
-    // -------------------------------------------------------------- Constants
 
+    // -------------------------------------------------------------- Constants
 
     protected static final String ENCODING_NAME = "identity";
     protected static final ByteChunk ENCODING = new ByteChunk();
@@ -152,17 +154,25 @@ public class IdentityInputFilter impleme
     }
 
 
-    /**
-     * End the current request.
-     */
-    public long end()
-        throws IOException {
+    public long end() throws IOException {
+
+        final int maxSwallowSize = 
org.apache.coyote.Constants.MAX_SWALLOW_SIZE;
+        final boolean maxSwallowSizeExceeded = (maxSwallowSize > -1 && 
remaining > maxSwallowSize);
+        long swallowed = 0;
 
         // Consume extra bytes.
         while (remaining > 0) {
+
             int nread = buffer.doRead(endChunk, null);
             if (nread > 0 ) {
+                swallowed += nread;
                 remaining = remaining - nread;
+                if (maxSwallowSizeExceeded && swallowed > maxSwallowSize) {
+                    // Note: We do not fail early so the client has a chance to
+                    // read the response before the connection is closed. See:
+                    // 
http://httpd.apache.org/docs/2.0/misc/fin_wait_2.html#appendix
+                    throw new 
IOException(sm.getString("inputFilter.maxSwallow"));
+                }
             } else { // errors are handled higher up.
                 remaining = 0;
             }

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/LocalStrings.properties?rev=1659537&r1=1659536&r2=1659537&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/LocalStrings.properties
 (original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/LocalStrings.properties
 Fri Feb 13 12:31:38 2015
@@ -22,4 +22,6 @@ chunkedInputFilter.invalidCrlfNoCR=Inval
 chunkedInputFilter.invalidCrlfNoData=Invalid end of line sequence (no data 
available to read)
 chunkedInputFilter.invalidHeader=Invalid chunk header
 chunkedInputFilter.maxExtension=maxExtensionSize exceeded
-chunkedInputFilter.maxTrailer=maxTrailerSize exceeded
\ No newline at end of file
+chunkedInputFilter.maxTrailer=maxTrailerSize exceeded
+
+inputFilter.maxSwallow=maxSwallowSize exceeded

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1659537&r1=1659536&r2=1659537&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Fri Feb 13 12:31:38 2015
@@ -65,6 +65,11 @@
         protocols case insensitive. Correct spelling of
         filterInsecureProtocols method. (kkolinko/schultz)
       </fix>
+      <fix>
+        When applying the <code>maxSwallowSize</code> limit to a connection 
read
+        that many bytes first before closing the connection to give the client 
a
+        chance to read the reponse. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">

Modified: tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml?rev=1659537&r1=1659536&r2=1659537&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/config/systemprops.xml Fri Feb 13 
12:31:38 2015
@@ -440,6 +440,14 @@
       <p>If not specified, the default value of <code>8192</code> will be 
used.</p>
     </property>
 
+    <property name="org.apache.coyote.MAX_SWALLOW_SIZE">
+      <p>Limits the length of a request body Tomcat will swallow if it is not
+      read during normal request processing. If the value is <code>-1</code>, 
no
+      limit will be imposed.</p>
+      <p>If not specified, the default value of <code>2097152</code> (2MB) will
+      be used.</p>
+    </property>
+
     <property name="catalina.useNaming">
       <p>If this is <code>false</code> it will override the
       <code>useNaming</code> attribute for all <a href="context.html">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to