mirror of https://github.com/milvus-io/milvus.git
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
parent
c0fa169d9a
commit
33801c32c4
|
@ -1466,7 +1466,11 @@ func ValidateSparseFloatRows(rows ...[]byte) error {
|
||||||
return fmt.Errorf("invalid data length in sparse float vector: %d", len(row))
|
return fmt.Errorf("invalid data length in sparse float vector: %d", len(row))
|
||||||
}
|
}
|
||||||
for i := 0; i < SparseFloatRowElementCount(row); i++ {
|
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")
|
return errors.New("unsorted indices in sparse float vector")
|
||||||
}
|
}
|
||||||
VerifyFloat(float64(SparseFloatRowValueAt(row, i)))
|
VerifyFloat(float64(SparseFloatRowValueAt(row, i)))
|
||||||
|
|
|
@ -18,6 +18,7 @@ package typeutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -2060,6 +2061,14 @@ func TestValidateSparseFloatRows(t *testing.T) {
|
||||||
assert.Error(t, err)
|
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) {
|
t.Run("empty indices or values", func(t *testing.T) {
|
||||||
rows := [][]byte{
|
rows := [][]byte{
|
||||||
testutils.CreateSparseFloatRow([]uint32{}, []float32{}),
|
testutils.CreateSparseFloatRow([]uint32{}, []float32{}),
|
||||||
|
|
Loading…
Reference in New Issue