mirror of https://github.com/apache/lucene.git
Add missing bounds check to PointRangeQuery for inclusive arrays.
Otherwise you may or may not get a strange exception.
This commit is contained in:
parent
b9d46e4fd6
commit
d21fe2e34a
|
@ -87,6 +87,12 @@ public abstract class PointRangeQuery extends Query {
|
||||||
if (upperPoint.length != numDims) {
|
if (upperPoint.length != numDims) {
|
||||||
throw new IllegalArgumentException("lowerPoint has length=" + numDims + " but upperPoint has different length=" + upperPoint.length);
|
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.lowerPoint = lowerPoint;
|
||||||
this.lowerInclusive = lowerInclusive;
|
this.lowerInclusive = lowerInclusive;
|
||||||
this.upperPoint = upperPoint;
|
this.upperPoint = upperPoint;
|
||||||
|
|
|
@ -1068,6 +1068,33 @@ public class TestPointQueries extends LuceneTestCase {
|
||||||
IOUtils.close(r, w, dir);
|
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 {
|
public void testWrongNumBytes() throws Exception {
|
||||||
Directory dir = newDirectory();
|
Directory dir = newDirectory();
|
||||||
IndexWriterConfig iwc = newIndexWriterConfig();
|
IndexWriterConfig iwc = newIndexWriterConfig();
|
||||||
|
|
Loading…
Reference in New Issue