fix: [Cherry-pick] in milvus check sparse index to be less than uint32 max (#32204)

issue: #29419
pr: #32199

Signed-off-by: Buqian Zheng <zhengbuqian@gmail.com>
pull/32211/head
Buqian Zheng 2024-04-12 14:53:19 +08:00 committed by GitHub
parent 6d7c6db49c
commit 64d9da117c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -1462,7 +1462,11 @@ func ValidateSparseFloatRows(rows ...[]byte) error {
return fmt.Errorf("invalid data length in sparse float vector: %d", len(row))
}
for i := 0; i < SparseFloatRowElementCount(row); i++ {
if i > 0 && SparseFloatRowIndexAt(row, i) < SparseFloatRowIndexAt(row, i-1) {
idx := SparseFloatRowIndexAt(row, i)
if idx == math.MaxUint32 {
return errors.New("invalid index in sparse float vector: must be less than 2^32-1")
}
if i > 0 && idx < SparseFloatRowIndexAt(row, i-1) {
return errors.New("unsorted indices in sparse float vector")
}
VerifyFloat(float64(SparseFloatRowValueAt(row, i)))

View File

@ -18,6 +18,7 @@ package typeutil
import (
"encoding/binary"
"math"
"reflect"
"testing"
@ -2060,6 +2061,14 @@ func TestValidateSparseFloatRows(t *testing.T) {
assert.Error(t, err)
})
t.Run("invalid index", func(t *testing.T) {
rows := [][]byte{
testutils.CreateSparseFloatRow([]uint32{3, 5, math.MaxUint32}, []float32{1.0, 2.0, 3.0}),
}
err := ValidateSparseFloatRows(rows...)
assert.Error(t, err)
})
t.Run("empty indices or values", func(t *testing.T) {
rows := [][]byte{
testutils.CreateSparseFloatRow([]uint32{}, []float32{}),