From 4f20bdf68b085e35cb9f877f99e7603c5cefc3d0 Mon Sep 17 00:00:00 2001 From: igerasim Date: Tue, 28 Nov 2017 14:10:28 -0800 Subject: [PATCH] 8189284: More refactoring for deserialization cases Reviewed-by: rriggs, igerasim, rhalade, skoivu --- .../util/concurrent/ArrayBlockingQueue.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java b/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java index a8f27ec82..4edabdb5b 100644 --- a/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java +++ b/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java @@ -1414,4 +1414,30 @@ public class ArrayBlockingQueue extends AbstractQueue Spliterator.CONCURRENT); } + /** + * Deserializes this queue and then checks some invariants. + * + * @param s the input stream + * @throws ClassNotFoundException if the class of a serialized object + * could not be found + * @throws java.io.InvalidObjectException if invariants are violated + * @throws java.io.IOException if an I/O error occurs + */ + private void readObject(java.io.ObjectInputStream s) + throws java.io.IOException, ClassNotFoundException { + + // Read in items array and various fields + s.defaultReadObject(); + + // Check invariants over count and index fields. Note that + // if putIndex==takeIndex, count can be either 0 or items.length. + if (items.length == 0 || + takeIndex < 0 || takeIndex >= items.length || + putIndex < 0 || putIndex >= items.length || + count < 0 || count > items.length || + Math.floorMod(putIndex - takeIndex, items.length) != + Math.floorMod(count, items.length)) { + throw new java.io.InvalidObjectException("invariants violated"); + } + } } -- GitLab