1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# HG changeset patch
# User dmeetry
# Date 1352295947 -14400
# Node ID ee4632a30696050ebd5c014fb3da64112ab48dd3
# Parent 6e2d4ed84b41667df189abb7bd0915cda01a85a0
7186954: Improve connection performance
Reviewed-by: khazra
diff --git a/src/share/classes/sun/net/httpserver/ChunkedInputStream.java b/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
--- jdk/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
+++ jdk/src/share/classes/sun/net/httpserver/ChunkedInputStream.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -41,8 +41,12 @@ class ChunkedInputStream extends LeftOve
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,9 +77,13 @@ class ChunkedInputStream extends LeftOve
char[] len_arr = new char [16];
int len_size = 0;
boolean end_of_len = false;
+ int read = 0;
while ((c=(char)in.read())!= -1) {
- 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) {
diff --git a/src/share/classes/sun/net/www/http/ChunkedInputStream.java b/src/share/classes/sun/net/www/http/ChunkedInputStream.java
--- jdk/src/share/classes/sun/net/www/http/ChunkedInputStream.java
+++ jdk/src/share/classes/sun/net/www/http/ChunkedInputStream.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -125,6 +125,11 @@ class ChunkedInputStream extends InputSt
*/
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 @@ class ChunkedInputStream extends InputSt
break;
}
pos++;
+ if ((pos - rawPos) >= MAX_CHUNK_HEADER_SIZE) {
+ error = true;
+ throw new IOException("Chunk header too long");
+ }
}
if (pos >= rawCount) {
return;
|