Author: violetagg
Date: Fri Nov 25 14:14:29 2016
New Revision: 1771316

URL: http://svn.apache.org/viewvc?rev=1771316&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=60400
When expanding the buffer used for reading the request body, ensure the read 
position will be restored to the original one.

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java
    tomcat/trunk/test/org/apache/catalina/connector/TestInputBuffer.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java?rev=1771316&r1=1771315&r2=1771316&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/InputBuffer.java Fri Nov 25 
14:14:29 2016
@@ -666,9 +666,11 @@ public class InputBuffer extends Reader
         }
 
         CharBuffer tmp = CharBuffer.allocate(newSize);
+        int oldPosition = cb.position();
         cb.position(0);
         tmp.put(cb);
         tmp.flip();
+        tmp.position(oldPosition);
         cb = tmp;
         tmp = null;
     }

Modified: tomcat/trunk/test/org/apache/catalina/connector/TestInputBuffer.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestInputBuffer.java?rev=1771316&r1=1771315&r2=1771316&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestInputBuffer.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestInputBuffer.java Fri 
Nov 25 14:14:29 2016
@@ -16,11 +16,13 @@
  */
 package org.apache.catalina.connector;
 
+import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Writer;
 import java.nio.charset.MalformedInputException;
 import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
 
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
@@ -59,6 +61,25 @@ public class TestInputBuffer extends Tom
     }
 
 
+    @Test
+    public void testBug60400() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        Context root = tomcat.addContext("", TEMP_DIR);
+        Tomcat.addServlet(root, "Bug60400Servlet", new Bug60400Servlet());
+        root.addServletMappingDecoded("/", "Bug60400Servlet");
+
+        tomcat.getConnector().setProperty("appReadBufSize", "9000");
+        tomcat.start();
+
+        ByteChunk bc = new ByteChunk();
+        byte[] requestBody = new byte[9500];
+        Arrays.fill(requestBody, (byte) 1); 
+        int rc = postUrl(requestBody, "http://localhost:"; + getPort() + "/", 
bc, null);
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+        Assert.assertEquals(requestBody.length, bc.getLength());
+    }
+
+
     private void doUtf8BodyTest(String description, int[] input,
             String expected) throws Exception {
 
@@ -118,4 +139,23 @@ public class TestInputBuffer extends Tom
             }
         }
     }
+
+
+    private static class Bug60400Servlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            StringBuilder builder = new StringBuilder();
+            try (BufferedReader reader = req.getReader()) {
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    builder.append(line);
+                }
+            }
+            resp.getWriter().print(builder);
+        }
+    }
 }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1771316&r1=1771315&r2=1771316&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Nov 25 14:14:29 2016
@@ -117,6 +117,11 @@
         along with the various constants used by the sub-classes to store the
         return value. (markt)
       </scode>
+      <fix>
+        <bug>60400</bug>: When expanding the buffer used for reading the
+        request body, ensure the read position will be restored to the
+        original one. (violetagg)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to