Apache Solr open-source search software
LUCENE-3876: don't corrupt the index (from wrong shift operator) for large documents
Robert Muir4f37e0f34145
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex c66ae9507bc..3b212d3859d 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -943,6 +943,10 @@ Bug fixesinteger overflow. This can happen, for example when using a buggyTokenStream that forgets to call clearAttributes() in combinationwith a StopFilter. (Robert Muir)++* LUCENE-3876: Fix bug where positions for a document exceeding+ Integer.MAX_VALUE/2 would produce a corrupt index.+ (Simon Willnauer, Mike Mccandless, Robert Muir)Optimizationsdiff --git a/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java b/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.javaindex ba75c9d9a62..25aa837a8cd 100644--- a/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java+++ b/lucene/core/src/java/org/apache/lucene/index/FreqProxTermsWriterPerField.java@@ -486,7 +486,7 @@ final class FreqProxTermsWriterPerField extends TermsHashConsumerPerField implemif (readPositions) {final int code = prox.readVInt();- position += code >> 1;+ position += code >>> 1;if ((code & 1) != 0) {diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.javaindex a4503dcc353..6c4fa4cede4 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterExceptions.java@@ -1517,4 +1517,20 @@ public class TestIndexWriterExceptions extends LuceneTestCase {iw.close();dir.close();}++ public void testLegalbutVeryLargePositions() throws Exception {+ Directory dir = newDirectory();+ IndexWriter iw = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, null));+ Document doc = new Document();+ Token t1 = new Token("foo", 0, 3);+ t1.setPositionIncrement(Integer.MAX_VALUE-500);+ TokenStream overflowingTokenStream = new CannedTokenStream(+ new Token[] { t1 }+ );+ Field field = new TextField("foo", overflowingTokenStream);+ doc.add(field);+ iw.addDocument(doc);+ iw.close();+ dir.close();+ }}