Skip to content

Commit

Permalink
MB-33028 - do not run match on empty data slice
Browse files Browse the repository at this point in the history
  • Loading branch information
nelio2k committed Feb 11, 2019
1 parent 3a0c03f commit f0cb6ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fastMatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func (m *FastMatcher) matchExec(token tokenType, tokenData []byte, node *ExecNod
}
}
} else {
panic("invalid token read")
panic(fmt.Sprintf("invalid token read - tokenType: %v data: %v", token, string(tokenData)))
}

if node.After != nil {
Expand Down Expand Up @@ -713,6 +713,10 @@ func (m *FastMatcher) matchObjectOrArray(token tokenType, tokenData []byte, node
func (m *FastMatcher) Match(data []byte) (bool, error) {
m.tokens.Reset(data)

if len(data) == 0 {
return false, nil
}

token, tokenData, err := m.tokens.Step()
if err != nil {
return false, err
Expand Down
13 changes: 13 additions & 0 deletions filterExprParser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ func TestFilterExpressionParser(t *testing.T) {
udMarsh, _ = json.Marshal(userData)
match, err = m.Match(udMarsh)
assert.True(match)
assert.Nil(err)

// Negative
_, _, err = NewFilterExpressionParser("fieldpath.`path = fieldPath2")
Expand All @@ -526,4 +527,16 @@ func TestFilterExpressionParser(t *testing.T) {
expr, err = fe.OutputExpression()
assert.Equal(ErrorMalformedParenthesis, err)

fe = &FilterExpression{}
err = parser.ParseString("TRUE", fe)
assert.Nil(err)
expr, err = fe.OutputExpression()
assert.Nil(err)
matchDef = trans.Transform([]Expression{expr})
assert.NotNil(matchDef)
m = NewFastMatcher(matchDef)
emptySlice := make([]byte, 0)
match, err = m.Match(emptySlice)
assert.False(match)
assert.Nil(err)
}

0 comments on commit f0cb6ab

Please sign in to comment.