From b99c8bbeb7ec11028d82bb3d408e588c5b5d913a Mon Sep 17 00:00:00 2001 From: Norbert Cyran Date: Fri, 9 Jan 2026 13:50:58 +0100 Subject: [PATCH] Prevent overflowing memory limits Memory limits can overflow, as they are multiplied by 1024^3. --- cluster-autoscaler/config/flags/flags.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cluster-autoscaler/config/flags/flags.go b/cluster-autoscaler/config/flags/flags.go index 364c35d030db..5bf55e6d9219 100644 --- a/cluster-autoscaler/config/flags/flags.go +++ b/cluster-autoscaler/config/flags/flags.go @@ -19,6 +19,7 @@ package flags import ( "flag" "fmt" + "math" "strconv" "strings" "time" @@ -262,9 +263,20 @@ func createAutoscalingOptions() config.AutoscalingOptions { if err != nil { klog.Fatalf("Failed to parse flags: %v", err) } + maxGiB := int64(math.MaxInt64 / units.GiB) // Convert memory limits to bytes. - minMemoryTotal = minMemoryTotal * units.GiB - maxMemoryTotal = maxMemoryTotal * units.GiB + if minMemoryTotal > maxGiB { + klog.Warning("Min memory limit overflowed, defaulting to 0") + minMemoryTotal = 0 + } else { + minMemoryTotal = minMemoryTotal * units.GiB + } + if maxMemoryTotal > maxGiB { + klog.Warning("Max memory limit overflowed, defaulting to MaxInt64") + maxMemoryTotal = math.MaxInt64 + } else { + maxMemoryTotal = maxMemoryTotal * units.GiB + } parsedGpuTotal, err := parseMultipleGpuLimits(*gpuTotal) if err != nil {