Skip to content

Commit

Permalink
fix panic when calling ST_POINTFROMWKB() with no arguments (#2121)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Nov 5, 2023
1 parent 857710f commit 422c3fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sql/expression/function/spatial/wkb.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ var _ sql.CollationCoercible = (*PointFromWKB)(nil)

// NewPointFromWKB creates a new point expression.
func NewPointFromWKB(args ...sql.Expression) (sql.Expression, error) {
if len(args) < 1 && len(args) > 3 {
if len(args) < 1 || len(args) > 3 {
return nil, sql.ErrInvalidArgumentNumber.New("ST_POINTFROMWKB", "1, 2, or 3", len(args))
}
return &PointFromWKB{expression.NaryExpression{ChildExpressions: args}}, nil
Expand Down
20 changes: 20 additions & 0 deletions sql/expression/function/spatial/wkb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,4 +592,24 @@ func TestGeomFromWKB(t *testing.T) {
require.NoError(err)
require.Equal(nil, v)
})

t.Run("empty args errors", func(t *testing.T) {
require := require.New(t)
_, err := NewPointFromWKB()
require.Error(err)
_, err = NewLineFromWKB()
require.Error(err)
_, err = NewPolyFromWKB()
require.Error(err)
_, err = NewMultiPoint()
require.Error(err)
_, err = NewMultiLineString()
require.Error(err)
_, err = NewMultiPolygon()
require.Error(err)
_, err = NewGeomFromWKB()
require.Error(err)
_, err = NewGeomCollFromWKB()
require.Error(err)
})
}

0 comments on commit 422c3fe

Please sign in to comment.