diff --git a/internal/driver/fetch.go b/internal/driver/fetch.go index 6d967a2037..0809cd0814 100644 --- a/internal/driver/fetch.go +++ b/internal/driver/fetch.go @@ -430,7 +430,9 @@ mapping: // Llvm buildid protocol: the first two characters of the build id // are used as directory, and the remaining part is in the filename. // e.g. `/ab/cdef0123456.debug` - fileNames = append(fileNames, filepath.Join(path, m.BuildID[:2], m.BuildID[2:]+".debug")) + if len(m.BuildID) >= 2 { + fileNames = append(fileNames, filepath.Join(path, m.BuildID[:2], m.BuildID[2:]+".debug")) + } } if m.File != "" { // Try both the basename and the full path, to support the same directory diff --git a/internal/driver/fetch_test.go b/internal/driver/fetch_test.go index 3dcd7bbd0c..36ec2f28a2 100644 --- a/internal/driver/fetch_test.go +++ b/internal/driver/fetch_test.go @@ -77,6 +77,10 @@ func TestSymbolizationPath(t *testing.T) { {"", "", "fghij10001", filepath.Join(tempdir, "pprof/binaries/fg/hij10001.debug"), 0}, {"/nowhere:/alternate/architecture", "/usr/bin/binary", "fedcb10000", "/usr/bin/binary", 1}, {"/nowhere:/alternate/architecture", "/usr/bin/binary", "abcde10002", "/usr/bin/binary", 1}, + // A single-character BuildID must not panic when the LLVM debug-file + // lookup slices BuildID[:2] / BuildID[2:]. Prior to the fix, this caused + // a "slice bounds out of range" panic. + {"", "/usr/bin/binary", "X", "/usr/bin/binary", 0}, } { os.Setenv("PPROF_BINARY_PATH", tc.env) p := &profile.Profile{