From ddc5437edbd31472a68b0d284d3a12497601a569 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Tue, 3 Dec 2024 12:23:59 -0500 Subject: [PATCH] fix: incorrect conversion between integer types To fix the problem, we need to ensure that the value parsed by strconv.ParseUint does not exceed the maximum value that an int can hold before converting it. We can achieve this by adding a bounds check before the conversion. If the value exceeds the maximum value of an int, we should handle it appropriately, such as by setting a default value or returning an error. Signed-off-by: Ryan Johnson --- .../resources/tanzupackageinstall/spec/cluster_scope.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/resources/tanzupackageinstall/spec/cluster_scope.go b/internal/resources/tanzupackageinstall/spec/cluster_scope.go index 922c7be75..688be028f 100644 --- a/internal/resources/tanzupackageinstall/spec/cluster_scope.go +++ b/internal/resources/tanzupackageinstall/spec/cluster_scope.go @@ -7,6 +7,7 @@ package spec import ( "encoding/json" + "math" "strconv" valid "github.com/asaskevich/govalidator" @@ -80,8 +81,12 @@ func ConstructSpecForClusterScope(d *schema.ResourceData) (spec *packageinstallm break } - finalIntNum := int(number) // Convert uint64 To int - v1[key] = finalIntNum + if number > math.MaxInt32 { + v1[key] = value.(string) + } else { + finalIntNum := int(number) // Convert uint64 To int + v1[key] = finalIntNum + } case valid.IsFloat(value.(string)): floatNum, err := strconv.ParseFloat(value.(string), 64) if err != nil {