0
0
Fork 0

fix panic in term range search

if min and max are the same term
and the term is in dictionary
and both in and max are set to exclusive
then we would panic attempting to access element -1 of a slice.

now, after trimming the slice, we recheck that the length is > 0
This commit is contained in:
Marty Schoch 2017-05-05 23:13:04 -04:00
parent 15cb7a505a
commit 87f693fc57
2 changed files with 13 additions and 0 deletions

View File

@ -64,6 +64,10 @@ func NewTermRangeSearcher(indexReader index.IndexReader,
if !*inclusiveMin && min != nil && string(min) == terms[0] {
terms = terms[1:]
// check again, as we might have removed only entry
if len(terms) < 1 {
return NewMatchNoneSearcher(indexReader)
}
}
// if our term list included the max, it would be the last item

View File

@ -157,6 +157,15 @@ func TestTermRangeSearch(t *testing.T) {
inclusiveMax: true,
want: nil,
},
// min and max same (and term exists), both exlusive
{
min: []byte("marty"),
max: []byte("marty"),
field: "name",
inclusiveMin: false,
inclusiveMax: false,
want: nil,
},
}
for _, test := range tests {