Skip to content

Apache Lucene open-source search software

LUCENE-4948: Fix stinkbug in PostingsHighlighter (wrong array sizing on some jvms)

Robert Muirc5a5a7733682
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 5f19509b0b7..2b5f8518486 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -42,6 +42,10 @@ Bug Fixes
* LUCENE-4935: CustomScoreQuery wrongly applied its query boost twice
(boost^2). (Robert Muir)
+* LUCENE-4948: Fixed ArrayIndexOutOfBoundsException in PostingsHighlighter
+ if you had a 64-bit JVM without compressed OOPS: IBM J9, or Oracle with
+ large heap/explicitly disabled. (Mike McCandless, Uwe Schindler, Robert Muir)
+
Optimizations
* LUCENE-4938: Don't use an unnecessarily large priority queue in IndexSearcher
diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java b/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java
index 259a88656a2..734869bece5 100644
--- a/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java
+++ b/lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java
@@ -42,12 +42,18 @@ public final class Passage {
void addMatch(int startOffset, int endOffset, BytesRef term) {
assert startOffset >= this.startOffset && startOffset <= this.endOffset;
if (numMatches == matchStarts.length) {
- matchStarts = ArrayUtil.grow(matchStarts, numMatches+1);
- matchEnds = ArrayUtil.grow(matchEnds, numMatches+1);
- BytesRef newMatchTerms[] = new BytesRef[ArrayUtil.oversize(numMatches+1, RamUsageEstimator.NUM_BYTES_OBJECT_REF)];
+ int newLength = ArrayUtil.oversize(numMatches+1, RamUsageEstimator.NUM_BYTES_OBJECT_REF);
+ int newMatchStarts[] = new int[newLength];
+ int newMatchEnds[] = new int[newLength];
+ BytesRef newMatchTerms[] = new BytesRef[newLength];
+ System.arraycopy(matchStarts, 0, newMatchStarts, 0, numMatches);
+ System.arraycopy(matchEnds, 0, newMatchEnds, 0, numMatches);
System.arraycopy(matchTerms, 0, newMatchTerms, 0, numMatches);
+ matchStarts = newMatchStarts;
+ matchEnds = newMatchEnds;
matchTerms = newMatchTerms;
}
+ assert matchStarts.length == matchEnds.length && matchEnds.length == matchTerms.length;
matchStarts[numMatches] = startOffset;
matchEnds[numMatches] = endOffset;
matchTerms[numMatches] = term;