提交 5aeaadd8 编写于 作者: X xuelei

6853793: OutOfMemoryError in sun.security.provider.certpath.OCSPChecker.check

Summary: allocate memory dynamically, keep reading until EOF.
Reviewed-by: weijun
上级 4112d670
/*
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2009 Sun Microsystems, Inc. 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
......@@ -351,18 +351,27 @@ class OCSPChecker extends PKIXCertPathChecker {
}
in = con.getInputStream();
byte[] response = null;
int total = 0;
int contentLength = con.getContentLength();
if (contentLength == -1) {
if (contentLength != -1) {
response = new byte[contentLength];
} else {
response = new byte[2048];
contentLength = Integer.MAX_VALUE;
}
byte[] response = new byte[contentLength];
int total = 0;
int count = 0;
while (count != -1 && total < contentLength) {
count = in.read(response, total, response.length - total);
while (total < contentLength) {
int count = in.read(response, total, response.length - total);
if (count < 0)
break;
total += count;
if (total >= response.length && total < contentLength) {
response = Arrays.copyOf(response, total * 2);
}
}
response = Arrays.copyOf(response, total);
OCSPResponse ocspResponse = new OCSPResponse(response, pkixParams,
responderCert);
......
/*
* Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
* Copyright 2003-2009 Sun Microsystems, Inc. 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
......@@ -32,6 +32,7 @@ import java.net.URL;
import java.net.HttpURLConnection;
import java.util.Iterator;
import java.util.Set;
import java.util.Arrays;
import sun.security.pkcs.*;
......@@ -137,23 +138,33 @@ public class HttpTimestamper implements Timestamper {
}
System.out.println();
}
verifyMimeType(connection.getContentType());
int total = 0;
int contentLength = connection.getContentLength();
if (contentLength == -1) {
if (contentLength != -1) {
replyBuffer = new byte[contentLength];
} else {
replyBuffer = new byte[2048];
contentLength = Integer.MAX_VALUE;
}
verifyMimeType(connection.getContentType());
replyBuffer = new byte[contentLength];
int total = 0;
int count = 0;
while (count != -1 && total < contentLength) {
count = input.read(replyBuffer, total,
while (total < contentLength) {
int count = input.read(replyBuffer, total,
replyBuffer.length - total);
if (count < 0)
break;
total += count;
if (total >= replyBuffer.length && total < contentLength) {
replyBuffer = Arrays.copyOf(replyBuffer, total * 2);
}
}
replyBuffer = Arrays.copyOf(replyBuffer, total);
if (DEBUG) {
System.out.println("received timestamp response (length=" +
replyBuffer.length + ")");
total + ")");
}
} finally {
if (input != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册