LUCENE-8034: use subtraction instead of addition to sidestep int overflow in SpanNotQuery

This commit is contained in:
Mike McCandless 2017-11-22 18:01:05 -05:00
parent 360328b7c6
commit 726ee05240
3 changed files with 13 additions and 2 deletions

View File

@ -107,6 +107,9 @@ Bug Fixes
* LUCENE-8045: ParallelLeafReader did not correctly report FieldInfo.dvGen
(Alan Woodward)
* LUCENE-8034: Use subtraction instead of addition to sidestep int
overflow in SpanNotQuery. (Hari Menon via Mike McCandless)
Optimizations
* LUCENE-8018: Smaller FieldInfos memory footprint by not retaining unnecessary

View File

@ -178,7 +178,7 @@ public final class SpanNotQuery extends SpanQuery {
}
// exclude end position far enough in current doc, check start position:
if (candidate.endPosition() + post <= excludeSpans.startPosition()) {
if (excludeSpans.startPosition() - post >= candidate.endPosition()) {
return AcceptStatus.YES;
} else {
return AcceptStatus.NO;

View File

@ -196,7 +196,15 @@ public class TestBasics extends LuceneTestCase {
assertTrue(searcher.explain(query, 801).getValue() > 0.0f);
assertTrue(searcher.explain(query, 891).getValue() > 0.0f);
}
public void testSpanNotNoOverflowOnLargeSpans() throws Exception {
SpanQuery near = spanNearOrderedQuery("field", 4, "eight", "one");
SpanQuery query = spanNotQuery(near, spanTermQuery("field", "forty"), Integer.MAX_VALUE, Integer.MAX_VALUE);
checkHits(query, new int[]
{801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891});
}
public void testSpanWithMultipleNotSingle() throws Exception {
SpanQuery near = spanNearOrderedQuery("field", 4, "eight", "one");
SpanQuery or = spanOrQuery("field", "forty");