Fix indexcheck division by zero bug (#18482)

See also: #18479

Signed-off-by: yangxuan <xuan.yang@zilliz.com>
This commit is contained in:
XuanYang-cn 2022-08-02 16:04:34 +08:00 committed by GitHub
parent efc5406e78
commit 43c7c1ff03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -204,7 +204,7 @@ func (adapter *IVFPQConfAdapter) checkPQParams(params map[string]string) bool {
return false
}
m, err := strconv.Atoi(mStr)
if err != nil { // invalid m
if err != nil || m == 0 { // invalid m
return false
}

View File

@ -138,6 +138,9 @@ func TestIVFPQConfAdapter_CheckTrain(t *testing.T) {
invalidParamsM[IndexMode] = GPUMode
invalidParamsM[DIM] = strconv.Itoa(65536)
invalidParamsMzero := copyParams(validParams)
invalidParamsMzero[IVFM] = "0"
cases := []struct {
params map[string]string
want bool
@ -152,6 +155,7 @@ func TestIVFPQConfAdapter_CheckTrain(t *testing.T) {
{invalidParamsWithoutIVF, false},
{invalidParamsIVF, false},
{invalidParamsM, false},
{invalidParamsMzero, false},
}
adapter := newIVFPQConfAdapter()