mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
Merge
This commit is contained in:
commit
7884ab9ccf
317 changed files with 46678 additions and 66838 deletions
|
@ -385,7 +385,8 @@ class FileInputStream extends InputStream
|
|||
synchronized (this) {
|
||||
fc = this.channel;
|
||||
if (fc == null) {
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, true, false, this);
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, true,
|
||||
false, false, this);
|
||||
if (closed) {
|
||||
try {
|
||||
// possible race with close(), benign since
|
||||
|
|
|
@ -410,7 +410,8 @@ class FileOutputStream extends OutputStream
|
|||
synchronized (this) {
|
||||
fc = this.channel;
|
||||
if (fc == null) {
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, false, true, this);
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, false,
|
||||
true, false, this);
|
||||
if (closed) {
|
||||
try {
|
||||
// possible race with close(), benign since
|
||||
|
|
|
@ -44,7 +44,6 @@ import java.util.concurrent.ConcurrentMap;
|
|||
|
||||
import static java.io.ObjectStreamClass.processQueue;
|
||||
|
||||
import jdk.internal.misc.ObjectStreamClassValidator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.misc.Unsafe;
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
|
@ -1282,6 +1281,33 @@ public class ObjectInputStream
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the given array type and length to ensure that creation of such
|
||||
* an array is permitted by this ObjectInputStream. The arrayType argument
|
||||
* must represent an actual array type.
|
||||
*
|
||||
* This private method is called via SharedSecrets.
|
||||
*
|
||||
* @param arrayType the array type
|
||||
* @param arrayLength the array length
|
||||
* @throws NullPointerException if arrayType is null
|
||||
* @throws IllegalArgumentException if arrayType isn't actually an array type
|
||||
* @throws NegativeArraySizeException if arrayLength is negative
|
||||
* @throws InvalidClassException if the filter rejects creation
|
||||
*/
|
||||
private void checkArray(Class<?> arrayType, int arrayLength) throws InvalidClassException {
|
||||
Objects.requireNonNull(arrayType);
|
||||
if (! arrayType.isArray()) {
|
||||
throw new IllegalArgumentException("not an array type");
|
||||
}
|
||||
|
||||
if (arrayLength < 0) {
|
||||
throw new NegativeArraySizeException();
|
||||
}
|
||||
|
||||
filterCheck(arrayType, arrayLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide access to the persistent fields read from the input stream.
|
||||
*/
|
||||
|
@ -1740,9 +1766,6 @@ public class ObjectInputStream
|
|||
throw new StreamCorruptedException(
|
||||
String.format("invalid type code: %02X", tc));
|
||||
}
|
||||
if (descriptor != null) {
|
||||
validateDescriptor(descriptor);
|
||||
}
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
|
@ -1770,6 +1793,10 @@ public class ObjectInputStream
|
|||
passHandle = NULL_HANDLE;
|
||||
|
||||
int numIfaces = bin.readInt();
|
||||
if (numIfaces > 65535) {
|
||||
throw new InvalidObjectException("interface limit exceeded: "
|
||||
+ numIfaces);
|
||||
}
|
||||
String[] ifaces = new String[numIfaces];
|
||||
for (int i = 0; i < numIfaces; i++) {
|
||||
ifaces[i] = bin.readUTF();
|
||||
|
@ -3978,20 +4005,8 @@ public class ObjectInputStream
|
|||
}
|
||||
}
|
||||
|
||||
private void validateDescriptor(ObjectStreamClass descriptor) {
|
||||
ObjectStreamClassValidator validating = validator;
|
||||
if (validating != null) {
|
||||
validating.validateDescriptor(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
// controlled access to ObjectStreamClassValidator
|
||||
private volatile ObjectStreamClassValidator validator;
|
||||
|
||||
private static void setValidator(ObjectInputStream ois, ObjectStreamClassValidator validator) {
|
||||
ois.validator = validator;
|
||||
}
|
||||
static {
|
||||
SharedSecrets.setJavaObjectInputStreamAccess(ObjectInputStream::setValidator);
|
||||
SharedSecrets.setJavaObjectInputStreamAccess(ObjectInputStream::checkArray);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,14 +32,19 @@ import java.lang.ref.WeakReference;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
import java.lang.reflect.Member;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PermissionCollection;
|
||||
import java.security.Permissions;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -53,7 +58,8 @@ import jdk.internal.reflect.CallerSensitive;
|
|||
import jdk.internal.reflect.Reflection;
|
||||
import jdk.internal.reflect.ReflectionFactory;
|
||||
import sun.reflect.misc.ReflectUtil;
|
||||
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.misc.JavaSecurityAccess;
|
||||
import static java.io.ObjectStreamField.*;
|
||||
|
||||
/**
|
||||
|
@ -176,6 +182,9 @@ public class ObjectStreamClass implements Serializable {
|
|||
|
||||
/** serialization-appropriate constructor, or null if none */
|
||||
private Constructor<?> cons;
|
||||
/** protection domains that need to be checked when calling the constructor */
|
||||
private ProtectionDomain[] domains;
|
||||
|
||||
/** class-defined writeObject method, or null if none */
|
||||
private Method writeObjectMethod;
|
||||
/** class-defined readObject method, or null if none */
|
||||
|
@ -508,6 +517,7 @@ public class ObjectStreamClass implements Serializable {
|
|||
cl, "readObjectNoData", null, Void.TYPE);
|
||||
hasWriteObjectData = (writeObjectMethod != null);
|
||||
}
|
||||
domains = getProtectionDomains(cons, cl);
|
||||
writeReplaceMethod = getInheritableMethod(
|
||||
cl, "writeReplace", null, Object.class);
|
||||
readResolveMethod = getInheritableMethod(
|
||||
|
@ -550,6 +560,65 @@ public class ObjectStreamClass implements Serializable {
|
|||
ObjectStreamClass() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a PermissionDomain that grants no permission.
|
||||
*/
|
||||
private ProtectionDomain noPermissionsDomain() {
|
||||
PermissionCollection perms = new Permissions();
|
||||
perms.setReadOnly();
|
||||
return new ProtectionDomain(null, perms);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregate the ProtectionDomains of all the classes that separate
|
||||
* a concrete class {@code cl} from its ancestor's class declaring
|
||||
* a constructor {@code cons}.
|
||||
*
|
||||
* If {@code cl} is defined by the boot loader, or the constructor
|
||||
* {@code cons} is declared by {@code cl}, or if there is no security
|
||||
* manager, then this method does nothing and {@code null} is returned.
|
||||
*
|
||||
* @param cons A constructor declared by {@code cl} or one of its
|
||||
* ancestors.
|
||||
* @param cl A concrete class, which is either the class declaring
|
||||
* the constructor {@code cons}, or a serializable subclass
|
||||
* of that class.
|
||||
* @return An array of ProtectionDomain representing the set of
|
||||
* ProtectionDomain that separate the concrete class {@code cl}
|
||||
* from its ancestor's declaring {@code cons}, or {@code null}.
|
||||
*/
|
||||
private ProtectionDomain[] getProtectionDomains(Constructor<?> cons,
|
||||
Class<?> cl) {
|
||||
ProtectionDomain[] domains = null;
|
||||
if (cons != null && cl.getClassLoader() != null
|
||||
&& System.getSecurityManager() != null) {
|
||||
Class<?> cls = cl;
|
||||
Class<?> fnscl = cons.getDeclaringClass();
|
||||
Set<ProtectionDomain> pds = null;
|
||||
while (cls != fnscl) {
|
||||
ProtectionDomain pd = cls.getProtectionDomain();
|
||||
if (pd != null) {
|
||||
if (pds == null) pds = new HashSet<>();
|
||||
pds.add(pd);
|
||||
}
|
||||
cls = cls.getSuperclass();
|
||||
if (cls == null) {
|
||||
// that's not supposed to happen
|
||||
// make a ProtectionDomain with no permission.
|
||||
// should we throw instead?
|
||||
if (pds == null) pds = new HashSet<>();
|
||||
else pds.clear();
|
||||
pds.add(noPermissionsDomain());
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pds != null) {
|
||||
domains = pds.toArray(new ProtectionDomain[0]);
|
||||
}
|
||||
}
|
||||
return domains;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes class descriptor representing a proxy class.
|
||||
*/
|
||||
|
@ -580,6 +649,7 @@ public class ObjectStreamClass implements Serializable {
|
|||
writeReplaceMethod = localDesc.writeReplaceMethod;
|
||||
readResolveMethod = localDesc.readResolveMethod;
|
||||
deserializeEx = localDesc.deserializeEx;
|
||||
domains = localDesc.domains;
|
||||
cons = localDesc.cons;
|
||||
}
|
||||
fieldRefl = getReflector(fields, localDesc);
|
||||
|
@ -666,6 +736,7 @@ public class ObjectStreamClass implements Serializable {
|
|||
if (deserializeEx == null) {
|
||||
deserializeEx = localDesc.deserializeEx;
|
||||
}
|
||||
domains = localDesc.domains;
|
||||
cons = localDesc.cons;
|
||||
}
|
||||
|
||||
|
@ -1006,7 +1077,35 @@ public class ObjectStreamClass implements Serializable {
|
|||
requireInitialized();
|
||||
if (cons != null) {
|
||||
try {
|
||||
return cons.newInstance();
|
||||
if (domains == null || domains.length == 0) {
|
||||
return cons.newInstance();
|
||||
} else {
|
||||
JavaSecurityAccess jsa = SharedSecrets.getJavaSecurityAccess();
|
||||
PrivilegedAction<?> pea = () -> {
|
||||
try {
|
||||
return cons.newInstance();
|
||||
} catch (InstantiationException
|
||||
| InvocationTargetException
|
||||
| IllegalAccessException x) {
|
||||
throw new UndeclaredThrowableException(x);
|
||||
}
|
||||
}; // Can't use PrivilegedExceptionAction with jsa
|
||||
try {
|
||||
return jsa.doIntersectionPrivilege(pea,
|
||||
AccessController.getContext(),
|
||||
new AccessControlContext(domains));
|
||||
} catch (UndeclaredThrowableException x) {
|
||||
Throwable cause = x.getCause();
|
||||
if (cause instanceof InstantiationException)
|
||||
throw (InstantiationException) cause;
|
||||
if (cause instanceof InvocationTargetException)
|
||||
throw (InvocationTargetException) cause;
|
||||
if (cause instanceof IllegalAccessException)
|
||||
throw (IllegalAccessException) cause;
|
||||
// not supposed to happen
|
||||
throw x;
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
// should not occur, as access checks have been suppressed
|
||||
throw new InternalError(ex);
|
||||
|
|
|
@ -298,7 +298,8 @@ public class RandomAccessFile implements DataOutput, DataInput, Closeable {
|
|||
synchronized (this) {
|
||||
fc = this.channel;
|
||||
if (fc == null) {
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, true, rw, this);
|
||||
this.channel = fc = FileChannelImpl.open(fd, path, true,
|
||||
rw, false, this);
|
||||
if (closed.get()) {
|
||||
try {
|
||||
fc.close();
|
||||
|
|
|
@ -2166,7 +2166,7 @@ public abstract class ClassLoader {
|
|||
* @spec JPMS
|
||||
*
|
||||
* @jvms 5.3 Run-time package
|
||||
* @see <a href="{@docRoot}/../specs/jar/jar.html#sealing">
|
||||
* @see <a href="{@docRoot}/../specs/jar/jar.html#package-sealing">
|
||||
* The JAR File Specification: Package Sealing</a>
|
||||
*/
|
||||
protected Package definePackage(String name, String specTitle,
|
||||
|
|
|
@ -109,7 +109,7 @@ import jdk.internal.reflect.Reflection;
|
|||
* and have no specification and implementation versioning information.
|
||||
*
|
||||
* @jvms 5.3 Run-time package
|
||||
* @see <a href="{@docRoot}/../specs/jar/jar.html#sealing">
|
||||
* @see <a href="{@docRoot}/../specs/jar/jar.html#package-sealing">
|
||||
* The JAR File Specification: Package Sealing</a>
|
||||
* @see ClassLoader#definePackage(String, String, String, String, String, String, String, URL)
|
||||
*
|
||||
|
|
|
@ -2664,6 +2664,7 @@ public final class String
|
|||
* point</a> is passed through uninterpreted.
|
||||
*
|
||||
* @return an IntStream of char values from this sequence
|
||||
* @since 9
|
||||
*/
|
||||
@Override
|
||||
public IntStream chars() {
|
||||
|
@ -2683,6 +2684,7 @@ public final class String
|
|||
* {@code int} values which are then passed to the stream.
|
||||
*
|
||||
* @return an IntStream of Unicode code points from this sequence
|
||||
* @since 9
|
||||
*/
|
||||
@Override
|
||||
public IntStream codePoints() {
|
||||
|
|
|
@ -88,7 +88,7 @@ final class WeakPairMap<K1, K2, V> {
|
|||
* Maps the specified key pair to the specified value in this WeakPairMap.
|
||||
* Neither the keys nor the value can be null.
|
||||
* <p>The value can be retrieved by calling the {@link #get} method
|
||||
* with the the same keys (compared by identity).
|
||||
* with the same keys (compared by identity).
|
||||
*
|
||||
* @param k1 the 1st of the pair of keys with which the specified value is to
|
||||
* be associated
|
||||
|
|
|
@ -1196,7 +1196,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.*;
|
|||
|
||||
static
|
||||
MethodHandle bindCaller(MethodHandle mh, Class<?> hostClass) {
|
||||
// Code in the the boot layer should now be careful while creating method handles or
|
||||
// Code in the boot layer should now be careful while creating method handles or
|
||||
// functional interface instances created from method references to @CallerSensitive methods,
|
||||
// it needs to be ensured the handles or interface instances are kept safe and are not passed
|
||||
// from the boot layer to untrusted code.
|
||||
|
|
|
@ -195,7 +195,7 @@ public final class StringConcatFactory {
|
|||
// In case we need to double-back onto the StringConcatFactory during this
|
||||
// static initialization, make sure we have the reasonable defaults to complete
|
||||
// the static initialization properly. After that, actual users would use the
|
||||
// the proper values we have read from the the properties.
|
||||
// the proper values we have read from the properties.
|
||||
STRATEGY = DEFAULT_STRATEGY;
|
||||
// CACHE_ENABLE = false; // implied
|
||||
// CACHE = null; // implied
|
||||
|
@ -398,8 +398,8 @@ public final class StringConcatFactory {
|
|||
* <p>Then the following linkage invariants must hold:
|
||||
*
|
||||
* <ul>
|
||||
* <li>The parameter count in {@code concatType} is less than or equal to 200</li>
|
||||
*
|
||||
* <li>The number of parameter slots in {@code concatType} is
|
||||
* less than or equal to 200</li>
|
||||
* <li>The return type in {@code concatType} is assignable from {@link java.lang.String}</li>
|
||||
* </ul>
|
||||
*
|
||||
|
@ -487,8 +487,8 @@ public final class StringConcatFactory {
|
|||
* <p>Then the following linkage invariants must hold:
|
||||
*
|
||||
* <ul>
|
||||
* <li>The parameter count in {@code concatType} is less than or equal to
|
||||
* 200</li>
|
||||
* <li>The number of parameter slots in {@code concatType} is less than
|
||||
* or equal to 200</li>
|
||||
*
|
||||
* <li>The parameter count in {@code concatType} equals to number of \1 tags
|
||||
* in {@code recipe}</li>
|
||||
|
@ -613,9 +613,9 @@ public final class StringConcatFactory {
|
|||
concatType.returnType());
|
||||
}
|
||||
|
||||
if (concatType.parameterCount() > MAX_INDY_CONCAT_ARG_SLOTS) {
|
||||
if (concatType.parameterSlotCount() > MAX_INDY_CONCAT_ARG_SLOTS) {
|
||||
throw new StringConcatException("Too many concat argument slots: " +
|
||||
concatType.parameterCount() +
|
||||
concatType.parameterSlotCount() +
|
||||
", can only accept " +
|
||||
MAX_INDY_CONCAT_ARG_SLOTS);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2017, 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
|
||||
|
@ -111,6 +111,31 @@ public abstract class FileStore {
|
|||
*/
|
||||
public abstract long getUsableSpace() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the number of bytes per block in this file store.
|
||||
*
|
||||
* <p> File storage is typically organized into discrete sequences of bytes
|
||||
* called <i>blocks</i>. A block is the smallest storage unit of a file store.
|
||||
* Every read and write operation is performed on a multiple of blocks.
|
||||
*
|
||||
* @implSpec The implementation in this class throws an
|
||||
* {@code UnsupportedOperationException}.
|
||||
*
|
||||
* @return a positive value representing the block size of this file store,
|
||||
* in bytes
|
||||
*
|
||||
* @throws IOException
|
||||
* if an I/O error occurs
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* if the operation is not supported
|
||||
*
|
||||
* @since 10
|
||||
*/
|
||||
public long getBlockSize() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of unallocated bytes in the file store.
|
||||
*
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
import java.security.cert.*;
|
||||
import sun.net.util.URLUtil;
|
||||
import sun.security.util.IOUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -571,6 +572,8 @@ public class CodeSource implements java.io.Serializable {
|
|||
// could all be present in the stream at the same time
|
||||
cfs = new Hashtable<>(3);
|
||||
certList = new ArrayList<>(size > 20 ? 20 : size);
|
||||
} else if (size < 0) {
|
||||
throw new IOException("size cannot be negative");
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
|
@ -592,13 +595,7 @@ public class CodeSource implements java.io.Serializable {
|
|||
cfs.put(certType, cf);
|
||||
}
|
||||
// parse the certificate
|
||||
byte[] encoded = null;
|
||||
try {
|
||||
encoded = new byte[ois.readInt()];
|
||||
} catch (OutOfMemoryError oome) {
|
||||
throw new IOException("Certificate too big");
|
||||
}
|
||||
ois.readFully(encoded);
|
||||
byte[] encoded = IOUtils.readNBytes(ois, ois.readInt());
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
|
||||
try {
|
||||
certList.add(cf.generateCertificate(bais));
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
|
@ -25,12 +25,16 @@
|
|||
|
||||
package java.security;
|
||||
|
||||
import sun.security.util.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.lang.reflect.*;
|
||||
import java.security.cert.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The UnresolvedPermission class is used to hold Permissions that
|
||||
|
@ -550,6 +554,7 @@ implements java.io.Serializable
|
|||
{
|
||||
CertificateFactory cf;
|
||||
Hashtable<String, CertificateFactory> cfs = null;
|
||||
List<Certificate> certList = null;
|
||||
|
||||
ois.defaultReadObject();
|
||||
|
||||
|
@ -562,7 +567,9 @@ implements java.io.Serializable
|
|||
// we know of 3 different cert types: X.509, PGP, SDSI, which
|
||||
// could all be present in the stream at the same time
|
||||
cfs = new Hashtable<>(3);
|
||||
this.certs = new java.security.cert.Certificate[size];
|
||||
certList = new ArrayList<>(size > 20 ? 20 : size);
|
||||
} else if (size < 0) {
|
||||
throw new IOException("size cannot be negative");
|
||||
}
|
||||
|
||||
for (int i=0; i<size; i++) {
|
||||
|
@ -584,20 +591,18 @@ implements java.io.Serializable
|
|||
cfs.put(certType, cf);
|
||||
}
|
||||
// parse the certificate
|
||||
byte[] encoded=null;
|
||||
try {
|
||||
encoded = new byte[ois.readInt()];
|
||||
} catch (OutOfMemoryError oome) {
|
||||
throw new IOException("Certificate too big");
|
||||
}
|
||||
ois.readFully(encoded);
|
||||
byte[] encoded = IOUtils.readNBytes(ois, ois.readInt());
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
|
||||
try {
|
||||
this.certs[i] = cf.generateCertificate(bais);
|
||||
certList.add(cf.generateCertificate(bais));
|
||||
} catch (CertificateException ce) {
|
||||
throw new IOException(ce.getMessage());
|
||||
}
|
||||
bais.close();
|
||||
}
|
||||
if (certList != null) {
|
||||
this.certs = certList.toArray(
|
||||
new java.security.cert.Certificate[size]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2007, 2017, 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
|
||||
|
@ -34,6 +34,7 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import javax.security.auth.x500.X500Principal;
|
||||
|
||||
import sun.security.util.IOUtils;
|
||||
import sun.security.util.ObjectIdentifier;
|
||||
import sun.security.x509.InvalidityDateExtension;
|
||||
|
||||
|
@ -230,17 +231,17 @@ public class CertificateRevokedException extends CertificateException {
|
|||
int size = ois.readInt();
|
||||
if (size == 0) {
|
||||
extensions = Collections.emptyMap();
|
||||
} else if (size < 0) {
|
||||
throw new IOException("size cannot be negative");
|
||||
} else {
|
||||
extensions = new HashMap<>(size);
|
||||
extensions = new HashMap<>(size > 20 ? 20 : size);
|
||||
}
|
||||
|
||||
// Read in the extensions and put the mappings in the extensions map
|
||||
for (int i = 0; i < size; i++) {
|
||||
String oid = (String) ois.readObject();
|
||||
boolean critical = ois.readBoolean();
|
||||
int length = ois.readInt();
|
||||
byte[] extVal = new byte[length];
|
||||
ois.readFully(extVal);
|
||||
byte[] extVal = IOUtils.readNBytes(ois, ois.readInt());
|
||||
Extension ext = sun.security.x509.Extension.newExtension
|
||||
(new ObjectIdentifier(oid), critical, extVal);
|
||||
extensions.put(oid, ext);
|
||||
|
|
|
@ -38,6 +38,7 @@ import java.io.Serializable;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* Resizable-array implementation of the {@link Deque} interface. Array
|
||||
|
@ -1194,6 +1195,7 @@ public class ArrayDeque<E> extends AbstractCollection<E>
|
|||
|
||||
// Read in size and allocate array
|
||||
int size = s.readInt();
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size + 1);
|
||||
elements = new Object[size + 1];
|
||||
this.tail = size;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
|
@ -28,6 +28,7 @@ package java.util;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* Resizable-array implementation of the {@code List} interface. Implements
|
||||
|
@ -814,6 +815,7 @@ public class ArrayList<E> extends AbstractList<E>
|
|||
|
||||
if (size > 0) {
|
||||
// like clone(), allocate array based upon size not capacity
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size);
|
||||
Object[] elements = new Object[size];
|
||||
|
||||
// Read in all elements in the proper order.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
|
@ -34,6 +34,7 @@ import java.util.function.BiConsumer;
|
|||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* Hash table based implementation of the {@code Map} interface. This
|
||||
|
@ -1448,6 +1449,10 @@ public class HashMap<K,V> extends AbstractMap<K,V>
|
|||
float ft = (float)cap * lf;
|
||||
threshold = ((cap < MAXIMUM_CAPACITY && ft < MAXIMUM_CAPACITY) ?
|
||||
(int)ft : Integer.MAX_VALUE);
|
||||
|
||||
// Check Map.Entry[].class since it's the nearest public type to
|
||||
// what we're actually creating.
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, cap);
|
||||
@SuppressWarnings({"rawtypes","unchecked"})
|
||||
Node<K,V>[] tab = (Node<K,V>[])new Node[cap];
|
||||
table = tab;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2017, 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
|
||||
|
@ -26,6 +26,7 @@
|
|||
package java.util;
|
||||
|
||||
import java.io.InvalidObjectException;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* This class implements the {@code Set} interface, backed by a hash table
|
||||
|
@ -322,6 +323,13 @@ public class HashSet<E>
|
|||
capacity = (int) Math.min(size * Math.min(1 / loadFactor, 4.0f),
|
||||
HashMap.MAXIMUM_CAPACITY);
|
||||
|
||||
// Constructing the backing map will lazily create an array when the first element is
|
||||
// added, so check it before construction. Call HashMap.tableSizeFor to compute the
|
||||
// actual allocation size. Check Map.Entry[].class since it's the nearest public type to
|
||||
// what is actually created.
|
||||
SharedSecrets.getJavaObjectInputStreamAccess()
|
||||
.checkArray(s, Map.Entry[].class, HashMap.tableSizeFor(capacity));
|
||||
|
||||
// Create backing HashMap
|
||||
map = (((HashSet<?>)this) instanceof LinkedHashSet ?
|
||||
new LinkedHashMap<>(capacity, loadFactor) :
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 2017, 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
|
||||
|
@ -29,6 +29,7 @@ import java.io.*;
|
|||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.BiFunction;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* This class implements a hash table, which maps keys to values. Any
|
||||
|
@ -1291,6 +1292,10 @@ public class Hashtable<K,V>
|
|||
if (length > elements && (length & 1) == 0)
|
||||
length--;
|
||||
length = Math.min(length, origlength);
|
||||
|
||||
// Check Map.Entry[].class since it's the nearest public type to
|
||||
// what we're actually creating.
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Map.Entry[].class, length);
|
||||
table = new Entry<?,?>[length];
|
||||
threshold = (int)Math.min(length * loadFactor, MAX_ARRAY_SIZE + 1);
|
||||
count = 0;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2017, 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
|
||||
|
@ -29,6 +29,7 @@ import java.lang.reflect.Array;
|
|||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* This class implements the {@code Map} interface with a hash table, using
|
||||
|
@ -1304,7 +1305,9 @@ public class IdentityHashMap<K,V>
|
|||
if (size < 0)
|
||||
throw new java.io.StreamCorruptedException
|
||||
("Illegal mappings count: " + size);
|
||||
init(capacity(size));
|
||||
int cap = capacity(size);
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, cap);
|
||||
init(cap);
|
||||
|
||||
// Read the keys and values, and put the mappings in the table
|
||||
for (int i=0; i<size; i++) {
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.function.BiFunction;
|
|||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.vm.annotation.Stable;
|
||||
|
||||
/**
|
||||
|
@ -885,6 +886,7 @@ final class CollSer implements Serializable {
|
|||
throw new InvalidObjectException("negative length " + len);
|
||||
}
|
||||
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(ois, Object[].class, len);
|
||||
Object[] a = new Object[len];
|
||||
for (int i = 0; i < len; i++) {
|
||||
a[i] = ois.readObject();
|
||||
|
|
|
@ -1909,7 +1909,7 @@ public final class Locale implements Cloneable, Serializable {
|
|||
* Returns a name for the locale that is appropriate for display to the
|
||||
* user. This will be the values returned by getDisplayLanguage(),
|
||||
* getDisplayScript(), getDisplayCountry(), and getDisplayVariant() assembled
|
||||
* into a single string. The the non-empty values are used in order,
|
||||
* into a single string. The non-empty values are used in order,
|
||||
* with the second and subsequent names in parentheses. For example:
|
||||
* <blockquote>
|
||||
* language (script, country, variant)<br>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2017, 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
|
||||
|
@ -26,6 +26,7 @@
|
|||
package java.util;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* An unbounded priority {@linkplain Queue queue} based on a priority heap.
|
||||
|
@ -795,6 +796,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
|
|||
// Read in (and discard) array length
|
||||
s.readInt();
|
||||
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, size);
|
||||
queue = new Object[size];
|
||||
|
||||
// Read in all elements.
|
||||
|
|
|
@ -42,6 +42,7 @@ import java.util.function.BiConsumer;
|
|||
import java.util.function.BiFunction;
|
||||
import java.util.function.Function;
|
||||
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
import jdk.internal.util.xml.PropertiesDefaultHandler;
|
||||
|
||||
/**
|
||||
|
@ -1441,6 +1442,16 @@ class Properties extends Hashtable<Object,Object> {
|
|||
throw new StreamCorruptedException("Illegal # of Elements: " + elements);
|
||||
}
|
||||
|
||||
// Constructing the backing map will lazily create an array when the first element is
|
||||
// added, so check it before construction. Note that CHM's constructor takes a size
|
||||
// that is the number of elements to be stored -- not the table size -- so it must be
|
||||
// inflated by the default load factor of 0.75, then inflated to the next power of two.
|
||||
// (CHM uses the same power-of-two computation as HashMap, and HashMap.tableSizeFor is
|
||||
// accessible here.) Check Map.Entry[].class since it's the nearest public type to
|
||||
// what is actually created.
|
||||
SharedSecrets.getJavaObjectInputStreamAccess()
|
||||
.checkArray(s, Map.Entry[].class, HashMap.tableSizeFor((int)(elements / 0.75)));
|
||||
|
||||
// create CHM of appropriate capacity
|
||||
map = new ConcurrentHashMap<>(elements);
|
||||
|
||||
|
|
|
@ -1409,7 +1409,7 @@ public final class ServiceLoader<S>
|
|||
*
|
||||
* <p> To achieve laziness the actual work of locating providers is done
|
||||
* when processing the stream. If a service provider cannot be loaded for any
|
||||
* of the the reasons specified in the <a href="#errors">Errors</a> section
|
||||
* of the reasons specified in the <a href="#errors">Errors</a> section
|
||||
* above then {@link ServiceConfigurationError} is thrown by whatever method
|
||||
* caused the service provider to be loaded. </p>
|
||||
*
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1996, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1996, 2017, 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,6 +41,7 @@ package java.util;
|
|||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InvalidObjectException;
|
||||
import sun.util.calendar.CalendarSystem;
|
||||
import sun.util.calendar.CalendarUtils;
|
||||
import sun.util.calendar.BaseCalendar;
|
||||
|
@ -1278,6 +1279,9 @@ public class SimpleTimeZone extends TimeZone {
|
|||
*/
|
||||
private int serialVersionOnStream = currentSerialVersion;
|
||||
|
||||
// Maximum number of rules.
|
||||
private static final int MAX_RULE_NUM = 6;
|
||||
|
||||
private synchronized void invalidateCache() {
|
||||
cacheYear = startYear - 1;
|
||||
cacheStart = cacheEnd = 0;
|
||||
|
@ -1569,7 +1573,7 @@ public class SimpleTimeZone extends TimeZone {
|
|||
*/
|
||||
private byte[] packRules()
|
||||
{
|
||||
byte[] rules = new byte[6];
|
||||
byte[] rules = new byte[MAX_RULE_NUM];
|
||||
rules[0] = (byte)startDay;
|
||||
rules[1] = (byte)startDayOfWeek;
|
||||
rules[2] = (byte)endDay;
|
||||
|
@ -1594,7 +1598,7 @@ public class SimpleTimeZone extends TimeZone {
|
|||
endDayOfWeek = rules[3];
|
||||
|
||||
// As of serial version 2, include time modes
|
||||
if (rules.length >= 6) {
|
||||
if (rules.length >= MAX_RULE_NUM) {
|
||||
startTimeMode = rules[4];
|
||||
endTimeMode = rules[5];
|
||||
}
|
||||
|
@ -1691,9 +1695,13 @@ public class SimpleTimeZone extends TimeZone {
|
|||
// store the actual rules (which have not be made compatible with 1.1)
|
||||
// in the optional area. Read them in here and parse them.
|
||||
int length = stream.readInt();
|
||||
byte[] rules = new byte[length];
|
||||
stream.readFully(rules);
|
||||
unpackRules(rules);
|
||||
if (length <= MAX_RULE_NUM) {
|
||||
byte[] rules = new byte[length];
|
||||
stream.readFully(rules);
|
||||
unpackRules(rules);
|
||||
} else {
|
||||
throw new InvalidObjectException("Too many rules: " + length);
|
||||
}
|
||||
}
|
||||
|
||||
if (serialVersionOnStream >= 2) {
|
||||
|
|
|
@ -51,6 +51,7 @@ import java.util.Spliterators;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.UnaryOperator;
|
||||
import jdk.internal.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* A thread-safe variant of {@link java.util.ArrayList} in which all mutative
|
||||
|
@ -933,6 +934,7 @@ public class CopyOnWriteArrayList<E>
|
|||
|
||||
// Read in array length and allocate array
|
||||
int len = s.readInt();
|
||||
SharedSecrets.getJavaObjectInputStreamAccess().checkArray(s, Object[].class, len);
|
||||
Object[] elements = new Object[len];
|
||||
|
||||
// Read in all elements in the proper order.
|
||||
|
|
|
@ -568,7 +568,7 @@ public class Attributes implements Map<Object,Object>, Cloneable {
|
|||
/**
|
||||
* {@code Name} object for {@code Sealed} manifest attribute
|
||||
* used for sealing.
|
||||
* @see <a href="{@docRoot}/../specs/jar/jar.html#sealing">
|
||||
* @see <a href="{@docRoot}/../specs/jar/jar.html#package-sealing">
|
||||
* Package Sealing</a>
|
||||
*/
|
||||
public static final Name SEALED = new Name("Sealed");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue