Add missing bounds check to PointRangeQuery for inclusive arrays.

Otherwise you may or may not get a strange exception.
This commit is contained in:
Robert Muir 2016-02-25 14:03:21 -05:00
parent b9d46e4fd6
commit d21fe2e34a
2 changed files with 33 additions and 0 deletions

View File

@ -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;

View File

@ -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();