diff --git a/src/share/classes/com/sun/jndi/ldap/Connection.java b/src/share/classes/com/sun/jndi/ldap/Connection.java index 43e83c12b50782754ba18b43c05b74da300a8b69..e36670e34c6eaa638e5e3be35c82d64de34f83ae 100644 --- a/src/share/classes/com/sun/jndi/ldap/Connection.java +++ b/src/share/classes/com/sun/jndi/ldap/Connection.java @@ -47,8 +47,6 @@ import javax.naming.ldap.Control; import javax.net.ssl.SSLParameters; import javax.net.ssl.SSLSocket; -import sun.misc.IOUtils; - /** * A thread that creates a connection to an LDAP server. * After the connection, the thread reads from the connection. @@ -886,7 +884,7 @@ public final class Connection implements Runnable { } // read in seqlen bytes - byte[] left = IOUtils.readFully(in, seqlen, false); + byte[] left = readFully(in, seqlen); inbuf = Arrays.copyOf(inbuf, offset + left.length); System.arraycopy(left, 0, inbuf, offset, left.length); offset += left.length; @@ -981,6 +979,31 @@ System.err.println("bytesread: " + bytesread); } } + private static byte[] readFully(InputStream is, int length) + throws IOException + { + byte[] buf = new byte[Math.min(length, 8192)]; + int nread = 0; + while (nread < length) { + int bytesToRead; + if (nread >= buf.length) { // need to allocate a larger buffer + bytesToRead = Math.min(length - nread, buf.length + 8192); + if (buf.length < nread + bytesToRead) { + buf = Arrays.copyOf(buf, nread + bytesToRead); + } + } else { + bytesToRead = buf.length - nread; + } + int count = is.read(buf, nread, bytesToRead); + if (count < 0) { + if (buf.length != nread) + buf = Arrays.copyOf(buf, nread); + break; + } + nread += count; + } + return buf; + } // This code must be uncommented to run the LdapAbandonTest. /*public void sendSearchReqs(String dn, int numReqs) { diff --git a/src/share/classes/java/util/jar/JarFile.java b/src/share/classes/java/util/jar/JarFile.java index 940dfb679a4112b0dbfffd0fb44dd93706e437b9..dd6d1a413764cb92603217bb6d579b69612ed947 100644 --- a/src/share/classes/java/util/jar/JarFile.java +++ b/src/share/classes/java/util/jar/JarFile.java @@ -422,7 +422,12 @@ class JarFile extends ZipFile { */ private byte[] getBytes(ZipEntry ze) throws IOException { try (InputStream is = super.getInputStream(ze)) { - return IOUtils.readFully(is, (int)ze.getSize(), true); + int len = (int)ze.getSize(); + byte[] b = IOUtils.readAllBytes(is); + if (len != -1 && b.length != len) + throw new EOFException("Expected:" + len + ", read:" + b.length); + + return b; } } diff --git a/src/share/classes/sun/applet/AppletClassLoader.java b/src/share/classes/sun/applet/AppletClassLoader.java index f732ad224252dd80370d68fa43084b7d18fd9afd..1fcd1585ec27ec485822d920f8b44805c5553963 100644 --- a/src/share/classes/sun/applet/AppletClassLoader.java +++ b/src/share/classes/sun/applet/AppletClassLoader.java @@ -33,6 +33,7 @@ import java.net.URLConnection; import java.net.MalformedURLException; import java.net.InetAddress; import java.net.UnknownHostException; +import java.io.EOFException; import java.io.File; import java.io.FilePermission; import java.io.IOException; @@ -333,7 +334,9 @@ public class AppletClassLoader extends URLClassLoader { byte[] b; try { - b = IOUtils.readFully(in, len, true); + b = IOUtils.readAllBytes(in); + if (len != -1 && b.length != len) + throw new EOFException("Expected:" + len + ", read:" + b.length); } finally { in.close(); } diff --git a/src/share/classes/sun/reflect/misc/MethodUtil.java b/src/share/classes/sun/reflect/misc/MethodUtil.java index ebe802b60a2eff8d8f3f032fcaa22f66c75555bb..e48ec1d53ee4dc1f466336ec0a2a5f9c10b74d46 100644 --- a/src/share/classes/sun/reflect/misc/MethodUtil.java +++ b/src/share/classes/sun/reflect/misc/MethodUtil.java @@ -25,6 +25,7 @@ package sun.reflect.misc; +import java.io.EOFException; import java.security.AllPermission; import java.security.AccessController; import java.security.PermissionCollection; @@ -42,8 +43,8 @@ import java.lang.reflect.AccessibleObject; import java.lang.reflect.Modifier; import java.util.HashMap; import java.util.Map; -import sun.misc.IOUtils; +import sun.misc.IOUtils; class Trampoline { static { @@ -382,15 +383,12 @@ public final class MethodUtil extends SecureClassLoader { } } int len = uc.getContentLength(); - InputStream in = new BufferedInputStream(uc.getInputStream()); - - byte[] b; - try { - b = IOUtils.readFully(in, len, true); - } finally { - in.close(); + try (InputStream in = new BufferedInputStream(uc.getInputStream())) { + byte[] b = IOUtils.readAllBytes(in); + if (len != -1 && b.length != len) + throw new EOFException("Expected:" + len + ", read:" + b.length); + return b; } - return b; } diff --git a/src/share/classes/sun/security/timestamp/HttpTimestamper.java b/src/share/classes/sun/security/timestamp/HttpTimestamper.java index 50cef6ec04b198e614b3344cbe9564da4092ee49..9b646f74b5b9672c20b93cec2357d70dfcfe9597 100644 --- a/src/share/classes/sun/security/timestamp/HttpTimestamper.java +++ b/src/share/classes/sun/security/timestamp/HttpTimestamper.java @@ -27,6 +27,7 @@ package sun.security.timestamp; import java.io.BufferedInputStream; import java.io.DataOutputStream; +import java.io.EOFException; import java.io.IOException; import java.net.URI; import java.net.URL; @@ -147,8 +148,11 @@ public class HttpTimestamper implements Timestamper { } verifyMimeType(connection.getContentType()); - int contentLength = connection.getContentLength(); - replyBuffer = IOUtils.readFully(input, contentLength, false); + int clen = connection.getContentLength(); + replyBuffer = IOUtils.readAllBytes(input); + if (clen != -1 && replyBuffer.length != clen) + throw new EOFException("Expected:" + clen + + ", read:" + replyBuffer.length); if (debug != null) { debug.println("received timestamp response (length=" + diff --git a/test/sun/security/tools/jarsigner/TimestampCheck.java b/test/sun/security/tools/jarsigner/TimestampCheck.java index b5070ce11fb25fb7bab1f7c4f60716ca663622b2..1018ace05f9c680a583e54ad99880b1a6d94c872 100644 --- a/test/sun/security/tools/jarsigner/TimestampCheck.java +++ b/test/sun/security/tools/jarsigner/TimestampCheck.java @@ -743,7 +743,7 @@ public class TimestampCheck { try (JarFile jf = new JarFile(file)) { JarEntry je = jf.getJarEntry("META-INF/SIGNER.RSA"); try (InputStream is = jf.getInputStream(je)) { - byte[] content = IOUtils.readFully(is, -1, true); + byte[] content = IOUtils.readAllBytes(is); PKCS7 p7 = new PKCS7(content); SignerInfo[] si = p7.getSignerInfos(); if (si == null || si.length == 0) {