...
This exploit was mitigated in Java 1.7.0_03 by having the object of type AtomicReferenceArray<>
validate its array upon deserialization. The readObject()
method inspects the array contents, and if the array is of the wrong type, it copies the array, foiling the exploit. (Note that this is an example of using rule OBJ06-J. Defensively copy mutable inputs and mutable internal components.)
Code Block | ||||
---|---|---|---|---|
| ||||
public class AtomicReferenceArray<E> implements java.io.Serializable { private static final long serialVersionUID = -6209656149925076980L; // Rest of class... /** * Reconstitutes the instance from a stream (that is, deserializes it). * @param s the stream */ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { // Note: This must be changed if any additional fields are defined Object a = s.readFields().get("array", null); if (a == null || !a.getClass().isArray()) throw new java.io.InvalidObjectException("Not array type"); if (a.getClass() != Object[].class) a = Arrays.copyOf((Object[])a, Array.getLength(a), Object[].class); unsafe.putObjectVolatile(this, arrayFieldOffset, a); } } |
...