From ffb9bf06f5bf158bfdbb07a22fa7079748df8622 Mon Sep 17 00:00:00 2001 From: yihong Date: Fri, 20 Jun 2025 01:38:36 +0800 Subject: [PATCH] fix: string null value should error close #57143 (#61842) close pingcap/tidb#57143 --- pkg/types/vector.go | 6 ++++++ pkg/types/vector_test.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) 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"`)