fix: in milvus check sparse index to be less than uint32 max (#32199)

issue: #29419

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

View File

@ -1466,7 +1466,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{}),