limit the time a header read can take

pull/34/head
Zlatin Balevsky 2019-11-18 09:00:11 +00:00
parent df71ade69f
commit 9373d58b53
2 changed files with 4 additions and 0 deletions

View File

@ -11,6 +11,7 @@ public class Constants {
public static final int MAX_HEADER_SIZE = 0x1 << 14; public static final int MAX_HEADER_SIZE = 0x1 << 14;
public static final int MAX_HEADERS = 16; public static final int MAX_HEADERS = 16;
public static final long MAX_HEADER_TIME = 60 * 1000;
public static final int MAX_RESULTS = 0x1 << 16; public static final int MAX_RESULTS = 0x1 << 16;

View File

@ -91,9 +91,12 @@ public class DataUtil {
} }
public static String readTillRN(InputStream is) throws IOException { public static String readTillRN(InputStream is) throws IOException {
final long start = System.currentTimeMillis();
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
while(baos.size() < (Constants.MAX_HEADER_SIZE)) { while(baos.size() < (Constants.MAX_HEADER_SIZE)) {
int read = is.read(); int read = is.read();
if (System.currentTimeMillis() - start > Constants.MAX_HEADER_TIME)
throw new IOException("header taking too long");
if (read == -1) if (read == -1)
throw new IOException(); throw new IOException();
if (read == '\r') { if (read == '\r') {