mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8236862: Enhance support of Proxy class
Reviewed-by: smarks, chegar, skoivu, rhalade
This commit is contained in:
parent
29c68087c9
commit
036da9950b
1 changed files with 27 additions and 2 deletions
|
@ -31,6 +31,7 @@ import java.lang.System.Logger;
|
||||||
import java.lang.invoke.MethodHandle;
|
import java.lang.invoke.MethodHandle;
|
||||||
import java.lang.ref.ReferenceQueue;
|
import java.lang.ref.ReferenceQueue;
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
|
import java.lang.reflect.InvocationHandler;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.lang.reflect.Proxy;
|
import java.lang.reflect.Proxy;
|
||||||
import java.security.AccessControlContext;
|
import java.security.AccessControlContext;
|
||||||
|
@ -50,6 +51,7 @@ import jdk.internal.access.SharedSecrets;
|
||||||
import jdk.internal.misc.Unsafe;
|
import jdk.internal.misc.Unsafe;
|
||||||
import sun.reflect.misc.ReflectUtil;
|
import sun.reflect.misc.ReflectUtil;
|
||||||
import sun.security.action.GetBooleanAction;
|
import sun.security.action.GetBooleanAction;
|
||||||
|
import sun.security.action.GetIntegerAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An ObjectInputStream deserializes primitive data and objects previously
|
* An ObjectInputStream deserializes primitive data and objects previously
|
||||||
|
@ -303,6 +305,15 @@ public class ObjectInputStream
|
||||||
*/
|
*/
|
||||||
static final boolean SET_FILTER_AFTER_READ = GetBooleanAction
|
static final boolean SET_FILTER_AFTER_READ = GetBooleanAction
|
||||||
.privilegedGetProperty("jdk.serialSetFilterAfterRead");
|
.privilegedGetProperty("jdk.serialSetFilterAfterRead");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Property to override the implementation limit on the number
|
||||||
|
* of interfaces allowed for Proxies.
|
||||||
|
* The maximum number of interfaces allowed for a proxy is limited to 65535 by
|
||||||
|
* {@link java.lang.reflect.Proxy#newProxyInstance(ClassLoader, Class[], InvocationHandler)}.
|
||||||
|
*/
|
||||||
|
static final int PROXY_INTERFACE_LIMIT = Math.min(65535, GetIntegerAction
|
||||||
|
.privilegedGetProperty("jdk.serialProxyInterfaceLimit", 65535));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1915,14 +1926,23 @@ public class ObjectInputStream
|
||||||
|
|
||||||
int numIfaces = bin.readInt();
|
int numIfaces = bin.readInt();
|
||||||
if (numIfaces > 65535) {
|
if (numIfaces > 65535) {
|
||||||
throw new InvalidObjectException("interface limit exceeded: "
|
// Report specification limit exceeded
|
||||||
+ numIfaces);
|
throw new InvalidObjectException("interface limit exceeded: " +
|
||||||
|
numIfaces +
|
||||||
|
", limit: " + Caches.PROXY_INTERFACE_LIMIT);
|
||||||
}
|
}
|
||||||
String[] ifaces = new String[numIfaces];
|
String[] ifaces = new String[numIfaces];
|
||||||
for (int i = 0; i < numIfaces; i++) {
|
for (int i = 0; i < numIfaces; i++) {
|
||||||
ifaces[i] = bin.readUTF();
|
ifaces[i] = bin.readUTF();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recheck against implementation limit and throw with interface names
|
||||||
|
if (numIfaces > Caches.PROXY_INTERFACE_LIMIT) {
|
||||||
|
throw new InvalidObjectException("interface limit exceeded: " +
|
||||||
|
numIfaces +
|
||||||
|
", limit: " + Caches.PROXY_INTERFACE_LIMIT +
|
||||||
|
"; " + Arrays.toString(ifaces));
|
||||||
|
}
|
||||||
Class<?> cl = null;
|
Class<?> cl = null;
|
||||||
ClassNotFoundException resolveEx = null;
|
ClassNotFoundException resolveEx = null;
|
||||||
bin.setBlockDataMode(true);
|
bin.setBlockDataMode(true);
|
||||||
|
@ -1945,6 +1965,11 @@ public class ObjectInputStream
|
||||||
}
|
}
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (ClassNotFoundException ex) {
|
||||||
resolveEx = ex;
|
resolveEx = ex;
|
||||||
|
} catch (OutOfMemoryError memerr) {
|
||||||
|
IOException ex = new InvalidObjectException("Proxy interface limit exceeded: " +
|
||||||
|
Arrays.toString(ifaces));
|
||||||
|
ex.initCause(memerr);
|
||||||
|
throw ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call filterCheck on the class before reading anything else
|
// Call filterCheck on the class before reading anything else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue