changeset 5682:39e5407de46f

7186954: Improve connection performance Reviewed-by: chegar, skoivu
author khazra
date Thu, 18 Oct 2012 12:13:15 -0700
parents 553c80a99d3f
children a54d38f88b93
files src/share/classes/sun/net/httpserver/ChunkedInputStream.java src/share/classes/sun/net/www/http/ChunkedInputStream.java
diffstat 2 files changed, 20 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/net/httpserver/ChunkedInputStream.java	Fri Nov 02 15:16:27 2012 -0700
+++ b/src/share/classes/sun/net/httpserver/ChunkedInputStream.java	Thu Oct 18 12:13:15 2012 -0700
@@ -41,8 +41,12 @@
 
     private boolean needToReadHeader = true;
 
-    static char CR = '\r';
-    static char LF = '\n';
+    final static char CR = '\r';
+    final static char LF = '\n';
+    /*
+     * Maximum chunk header size of 2KB + 2 bytes for CRLF
+     */
+    private final static int MAX_CHUNK_HEADER_SIZE = 2050;
 
     private int numeric (char[] arr, int nchars) throws IOException {
         assert arr.length >= nchars;
@@ -73,10 +77,14 @@
         char[] len_arr = new char [16];
         int len_size = 0;
         boolean end_of_len = false;
+        int read = 0;
 
         while ((c=in.read())!= -1) {
             char ch = (char) c;
-            if (len_size == len_arr.length -1) {
+            read++;
+            if ((len_size == len_arr.length -1) ||
+                (read > MAX_CHUNK_HEADER_SIZE))
+            {
                 throw new IOException ("invalid chunk header");
             }
             if (gotCR) {
--- a/src/share/classes/sun/net/www/http/ChunkedInputStream.java	Fri Nov 02 15:16:27 2012 -0700
+++ b/src/share/classes/sun/net/www/http/ChunkedInputStream.java	Thu Oct 18 12:13:15 2012 -0700
@@ -125,6 +125,11 @@
      */
     private boolean closed;
 
+    /*
+     * Maximum chunk header size of 2KB + 2 bytes for CRLF
+     */
+    private final static int MAX_CHUNK_HEADER_SIZE = 2050;
+
     /**
      * State to indicate that next field should be :-
      *  chunk-size [ chunk-extension ] CRLF
@@ -290,6 +295,10 @@
                             break;
                         }
                         pos++;
+                        if ((pos - rawPos) >= MAX_CHUNK_HEADER_SIZE) {
+                            error = true;
+                            throw new IOException("Chunk header too long");
+                        }
                     }
                     if (pos >= rawCount) {
                         return;