fix: avoid unmarshal panic with incorrect map keys #3002 (#3013)

This commit is contained in:
Kevin Wan
2023-03-11 07:53:57 +08:00
committed by GitHub
parent 123c61ad12
commit 4cef2b412c
2 changed files with 19 additions and 0 deletions

View File

@@ -289,6 +289,10 @@ func (u *Unmarshaler) generateMap(keyType, elemType reflect.Type, mapValue any)
return reflect.ValueOf(mapValue), nil
}
if keyType != valueType.Key() {
return emptyValue, errTypeMismatch
}
refValue := reflect.ValueOf(mapValue)
targetValue := reflect.MakeMapWithSize(mapType, refValue.Len())
dereffedElemType := Deref(elemType)