You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2016/02/25 20:02:36 UTC

lucene-solr git commit: Add missing bounds check to PointRangeQuery for inclusive arrays.

Repository: lucene-solr
Updated Branches:
  refs/heads/master b9d46e4fd -> d21fe2e34


Add missing bounds check to PointRangeQuery for inclusive arrays.

Otherwise you may or may not get a strange exception.


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

Branch: refs/heads/master
Commit: d21fe2e34a743b824b3a026691f1cd3e2596a522
Parents: b9d46e4
Author: Robert Muir <rm...@apache.org>
Authored: Thu Feb 25 14:03:21 2016 -0500
Committer: Robert Muir <rm...@apache.org>
Committed: Thu Feb 25 14:03:55 2016 -0500

----------------------------------------------------------------------
 .../apache/lucene/search/PointRangeQuery.java   |  6 +++++
 .../apache/lucene/search/TestPointQueries.java  | 27 ++++++++++++++++++++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d21fe2e3/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
index c68715d..59f8f0f 100644
--- a/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
+++ b/lucene/core/src/java/org/apache/lucene/search/PointRangeQuery.java
@@ -87,6 +87,12 @@ public abstract class PointRangeQuery extends Query {
     if (upperPoint.length != numDims) {
       throw new IllegalArgumentException("lowerPoint has length=" + numDims + " but upperPoint has different length=" + upperPoint.length);
     }
+    if (lowerInclusive.length != numDims) {
+      throw new IllegalArgumentException("lowerInclusive has length=" + lowerInclusive.length + " but expected=" + numDims);
+    }
+    if (upperInclusive.length != numDims) {
+      throw new IllegalArgumentException("upperInclusive has length=" + upperInclusive.length + " but expected=" + numDims);
+    }
     this.lowerPoint = lowerPoint;
     this.lowerInclusive = lowerInclusive;
     this.upperPoint = upperPoint;

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/d21fe2e3/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
index 4a232a6..38d46e1 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestPointQueries.java
@@ -1068,6 +1068,33 @@ public class TestPointQueries extends LuceneTestCase {
     IOUtils.close(r, w, dir);
   }
 
+  /** ensure good exception when boolean[]s for inclusive have wrong length */
+  public void testWrongNumBooleans() throws Exception {
+    Directory dir = newDirectory();
+    IndexWriterConfig iwc = newIndexWriterConfig();
+    iwc.setCodec(getCodec());
+    RandomIndexWriter w = new RandomIndexWriter(random(), dir, iwc);
+    Document doc = new Document();
+    doc.add(new LongPoint("value", 1L, 2L));
+    w.addDocument(doc);
+
+    IndexReader r = w.getReader();
+
+    // no wrapping, else the exc might happen in executor thread:
+    IndexSearcher s = new IndexSearcher(r);
+    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
+      s.count(LongPoint.newMultiRangeQuery("value", new Long[] { 1L, 2L }, new boolean[] {true}, new Long[] { 1L, 2L }, new boolean[] {true, true}));
+    });
+    assertEquals("lowerInclusive has length=1 but expected=2", expected.getMessage());
+
+    expected = expectThrows(IllegalArgumentException.class, () -> {
+      s.count(LongPoint.newMultiRangeQuery("value", new Long[] { 1L, 2L }, new boolean[] {true, true}, new Long[] { 1L, 2L }, new boolean[] {true}));
+    });
+    assertEquals("upperInclusive has length=1 but expected=2", expected.getMessage());
+
+    IOUtils.close(r, w, dir);
+  }
+
   public void testWrongNumBytes() throws Exception {
     Directory dir = newDirectory();
     IndexWriterConfig iwc = newIndexWriterConfig();