lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject [05/50] lucene-solr:jira/solr-11458-2: LUCENE-8034: use subtraction instead of addition to sidestep int overflow in SpanNotQuery
Date Mon, 04 Dec 2017 17:48:49 GMT
LUCENE-8034: use subtraction instead of addition to sidestep int overflow in SpanNotQuery


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/726ee052
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/726ee052
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/726ee052

Branch: refs/heads/jira/solr-11458-2
Commit: 726ee05240a65badf6c3499dd1e29daf490a3e48
Parents: 360328b
Author: Mike McCandless <mikemccand@apache.org>
Authored: Wed Nov 22 18:01:05 2017 -0500
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Wed Nov 22 18:01:05 2017 -0500

----------------------------------------------------------------------
 lucene/CHANGES.txt                                        |  3 +++
 .../java/org/apache/lucene/search/spans/SpanNotQuery.java |  2 +-
 .../test/org/apache/lucene/search/spans/TestBasics.java   | 10 +++++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/726ee052/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index a77ea34..c7e0995 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -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

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/726ee052/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
index b169bd8..d8c7862 100644
--- a/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/spans/SpanNotQuery.java
@@ -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;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/726ee052/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java b/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java
index d699719..1941bae 100644
--- a/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java
+++ b/lucene/core/src/test/org/apache/lucene/search/spans/TestBasics.java
@@ -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");


Mime
View raw message