diff --git a/pkg/types/vector.go b/pkg/types/vector.go index 19e7b674e8..071230bc74 100644 --- a/pkg/types/vector.go +++ b/pkg/types/vector.go @@ -220,6 +220,12 @@ func ZeroCopyDeserializeVectorFloat32(b []byte) (VectorFloat32, []byte, error) { // ParseVectorFloat32 parses a string into a vector. func ParseVectorFloat32(s string) (VectorFloat32, error) { + // issue #57143 jsoniter parse null will return as [] + // Trim whitespace and check for null string and reject it + if strings.TrimSpace(s) == "null" { + return ZeroVectorFloat32, errors.Errorf("Invalid vector text: %s", s) + } + var values []float32 var valueError error // We explicitly use a JSON float parser to reject other JSON types. diff --git a/pkg/types/vector_test.go b/pkg/types/vector_test.go index cb59a19608..f954fb521b 100644 --- a/pkg/types/vector_test.go +++ b/pkg/types/vector_test.go @@ -61,9 +61,9 @@ func TestVectorParse(t *testing.T) { require.NotNil(t, err) require.True(t, v.IsZeroValue()) - // Note: Currently we will parse "null" into []. + // "null" string should return error, not empty vector v, err = types.ParseVectorFloat32(`null`) - require.Nil(t, err) + require.NotNil(t, err) require.True(t, v.IsZeroValue()) v, err = types.ParseVectorFloat32(`"json_str"`)