jdk/src/share/classes/sun/net/www/http/ChunkedInputStream.java

Print this page
rev 5672 : 7186954: Improve connection performance
Reviewed-by: chegar, skoivu

@@ -123,10 +123,15 @@
      * Indicates if the chunked stream has been closed using the
      * <code>close</code> method.
      */
     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
      */
     static final int STATE_AWAITING_CHUNK_HEADER    = 1;

@@ -288,10 +293,14 @@
                     while (pos < rawCount) {
                         if (rawData[pos] == '\n') {
                             break;
                         }
                         pos++;
+                        if ((pos - rawPos) >= MAX_CHUNK_HEADER_SIZE) {
+                            error = true;
+                            throw new IOException("Chunk header too long");
+                        }
                     }
                     if (pos >= rawCount) {
                         return;
                     }