Return empty rows for impossible ranges

If the high end of a range is below the low end of the range, there's
no values in it, so we can short-circuit that. If we don't, if the
low end is zero or higher, and the high end is below zero, we can
get very surprising behaviors, such as accepting values up to the
inverse of the high end. Add a test case for this and treat it the
same as a low range end above the field's maximum or a high end
below the field's minimum, returning an empty row immediately.
This commit is contained in:
Seebs 2020-04-10 13:24:08 -05:00
parent 9b002bcc24
commit 017e65cd99
2 changed files with 2 additions and 1 deletions

View file

@ -2233,7 +2233,7 @@ func (b *bsiGroup) baseValue(op pql.Token, value int64) (baseValue int64, outOfR
// baseValueBetween adjusts the min/max value to align with the range for Field.
func (b *bsiGroup) baseValueBetween(lo, hi int64) (baseValueLo, baseValueHi int64, outOfRange bool) {
min, max := b.bitDepthMin(), b.bitDepthMax()
if hi < min || lo > max {
if hi < min || lo > max || hi < lo {
return 0, 0, true
}

View file

@ -144,6 +144,7 @@ func TestBSIGroup_BaseValue(t *testing.T) {
{b1, 5, 20, 5, 20, false},
{b1, 20, 1005, 20, 255, false},
{b1, 1005, 2000, 0, 0, true},
{b1, 0, -1, 0, 0, true},
{b2, 5, 95, -95, -5, false},
{b2, 95, 120, -5, 20, false},