From dc30aef687768c61cf960f1985ee3c4aa299cf0b Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sun, 29 Mar 2026 11:08:49 +0200 Subject: [PATCH] builder: fix panic in findPackagePath when using -size short This fixes an "index out of range" panic that occurs when calculating binary sizes. The strings.SplitN operation in findPackagePath can sometimes return a slice with only one element, so we now verify the length of the slice before attempting to access the second element. Signed-off-by: deadprogram --- builder/sizes.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builder/sizes.go b/builder/sizes.go index 57fb36df6..0b407f96f 100644 --- a/builder/sizes.go +++ b/builder/sizes.go @@ -954,7 +954,11 @@ func findPackagePath(path string, packagePathMap map[string]string) (packagePath libPath := strings.TrimPrefix(path, filepath.Join(goenv.Get("TINYGOROOT"), "lib")+string(os.PathSeparator)) parts := strings.SplitN(libPath, string(os.PathSeparator), 2) packagePath = "C " + parts[0] - filename = parts[1] + if len(parts) > 1 { + filename = parts[1] + } else { + filename = parts[0] + } } else if prefix := filepath.Join(goenv.Get("TINYGOROOT"), "llvm-project", "compiler-rt"); strings.HasPrefix(path, prefix) { packagePath = "C compiler-rt" filename = strings.TrimPrefix(path, prefix+string(os.PathSeparator))