Apache Lucene open-source search software
SOLR-5661: catch too-large priority queue
Michael McCandless3ae719d025da
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 6504b6def56..18560665452 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -192,6 +192,9 @@ Bug fixeson Lucene 4.6 if any index segments were Lucene 4.0-4.5.(Littlestar, Mike McCandless, Shai Erera, Robert Muir)+* SOLR-5661: PriorityQueue now refuses to allocate itself if the+ incoming maxSize is too large (Raintung Li via Mike McCandless)+API Changes* LUCENE-5339: The facet module was simplified/reworked to make thediff --git a/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java b/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.javaindex ef658bc2bc0..9820751499a 100644--- a/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java+++ b/lucene/core/src/java/org/apache/lucene/util/PriorityQueue.java@@ -41,11 +41,11 @@ public abstract class PriorityQueue<T> {public PriorityQueue(int maxSize, boolean prepopulate) {size = 0;int heapSize;- if (0 == maxSize)+ if (0 == maxSize) {// We allocate 1 extra to avoid if statement in top()heapSize = 2;- else {- if (maxSize == Integer.MAX_VALUE) {+ } else {+ if (maxSize > ArrayUtil.MAX_ARRAY_LENGTH) {// Don't wrap heapSize to -1, in this case, which// causes a confusing NegativeArraySizeException.// Note that very likely this will simply then hit@@ -54,7 +54,8 @@ public abstract class PriorityQueue<T> {// in this case, but it's very unlikely in practice// one will actually insert this many objects into// the PQ:- heapSize = Integer.MAX_VALUE;+ // Throw exception to prevent confusing OOME:+ throw new IllegalArgumentException("maxSize must be <= " + ArrayUtil.MAX_ARRAY_LENGTH + "; got: " + maxSize);} else {// NOTE: we add +1 because all access to heap is// 1-based not 0-based. heap[0] is unused.@@ -183,8 +184,9 @@ public abstract class PriorityQueue<T> {size--;downHeap(); // adjust heapreturn result;- } else+ } else {return null;+ }}/**