提交 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -351,18 +351,27 @@ class OCSPChecker extends PKIXCertPathChecker { ...@@ -351,18 +351,27 @@ class OCSPChecker extends PKIXCertPathChecker {
} }
in = con.getInputStream(); in = con.getInputStream();
byte[] response = null;
int total = 0;
int contentLength = con.getContentLength(); int contentLength = con.getContentLength();
if (contentLength == -1) { if (contentLength != -1) {
response = new byte[contentLength];
} else {
response = new byte[2048];
contentLength = Integer.MAX_VALUE; contentLength = Integer.MAX_VALUE;
} }
byte[] response = new byte[contentLength]; while (total < contentLength) {
int total = 0; int count = in.read(response, total, response.length - total);
int count = 0; if (count < 0)
while (count != -1 && total < contentLength) { break;
count = in.read(response, total, response.length - total);
total += count; 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, OCSPResponse ocspResponse = new OCSPResponse(response, pkixParams,
responderCert); 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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,6 +32,7 @@ import java.net.URL; ...@@ -32,6 +32,7 @@ import java.net.URL;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.Arrays;
import sun.security.pkcs.*; import sun.security.pkcs.*;
...@@ -137,23 +138,33 @@ public class HttpTimestamper implements Timestamper { ...@@ -137,23 +138,33 @@ public class HttpTimestamper implements Timestamper {
} }
System.out.println(); System.out.println();
} }
verifyMimeType(connection.getContentType());
int total = 0;
int contentLength = connection.getContentLength(); int contentLength = connection.getContentLength();
if (contentLength == -1) { if (contentLength != -1) {
replyBuffer = new byte[contentLength];
} else {
replyBuffer = new byte[2048];
contentLength = Integer.MAX_VALUE; contentLength = Integer.MAX_VALUE;
} }
verifyMimeType(connection.getContentType());
replyBuffer = new byte[contentLength]; while (total < contentLength) {
int total = 0; int count = input.read(replyBuffer, total,
int count = 0;
while (count != -1 && total < contentLength) {
count = input.read(replyBuffer, total,
replyBuffer.length - total); replyBuffer.length - total);
if (count < 0)
break;
total += count; total += count;
if (total >= replyBuffer.length && total < contentLength) {
replyBuffer = Arrays.copyOf(replyBuffer, total * 2);
}
} }
replyBuffer = Arrays.copyOf(replyBuffer, total);
if (DEBUG) { if (DEBUG) {
System.out.println("received timestamp response (length=" + System.out.println("received timestamp response (length=" +
replyBuffer.length + ")"); total + ")");
} }
} finally { } finally {
if (input != null) { if (input != null) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册