From 8794b054817aee4ca99cbd6311626540dd09dc14 Mon Sep 17 00:00:00 2001 From: Al Johri Date: Sun, 19 Apr 2026 17:11:08 -0400 Subject: [PATCH] pkg/query: Fix nil panic in flamegraph table + top AddProfileLocation (flamegraph_table.go) and GenerateTopTable (top.go) both assume every Location.Line has a non-nil Function and panic with `runtime error: invalid memory address or nil pointer dereference` when a caller passes in an unsymbolized line. The same bug existed in pkg/query/flamegraph.go and was fixed in PR #3892 ("Fix nil panic when building flat flamegraph", dd07a1214a) by guarding with `if line.Function != nil`. The analogous call sites in flamegraph_table.go and top.go were missed by that patch. This commit adds the same guard in both: - AddProfileLocation: skip lines whose Function is nil - GenerateTopTable: only populate node.Meta.Function when present Reproducible on main (HEAD 43cd07b2d) against profile data ingested via OTLP from the OTel eBPF profiler where some locations are unresolved. Triggers REPORT_TYPE_FLAMEGRAPH_TABLE and REPORT_TYPE_TOP queries to crash the server with the stack: panic: runtime error: invalid memory address or nil pointer dereference github.com/parca-dev/parca/pkg/query.(*tableConverter).AddFunction(0xc00024e680, 0x0) pkg/query/flamegraph_table.go:312 github.com/parca-dev/parca/pkg/query.(*tableConverter).AddProfileLocation(...) pkg/query/flamegraph_table.go:284 --- pkg/query/flamegraph_table.go | 3 +++ pkg/query/top.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/query/flamegraph_table.go b/pkg/query/flamegraph_table.go index 2c687742c7e..1e19cc14353 100644 --- a/pkg/query/flamegraph_table.go +++ b/pkg/query/flamegraph_table.go @@ -279,6 +279,9 @@ func (c *tableConverter) AddProfileLocation(l *profile.Location) uint32 { lines := make([]*metastorev1alpha1.Line, 0, len(l.Lines)) for _, line := range l.Lines { + if line.Function == nil { + continue + } lines = append(lines, &metastorev1alpha1.Line{ Line: line.Line, FunctionIndex: c.AddFunction(line.Function), diff --git a/pkg/query/top.go b/pkg/query/top.go index f8c829f1abe..a44889d1ddb 100644 --- a/pkg/query/top.go +++ b/pkg/query/top.go @@ -52,7 +52,7 @@ func GenerateTopTable(ctx context.Context, p parcaprofile.OldProfile) (*pb.Top, }, }, } - if len(location.Lines) > 0 { + if len(location.Lines) > 0 && location.Lines[0].Function != nil { // TODO: Return or merge multiple lines for samples node.Meta.Function = location.Lines[0].Function node.Meta.Line = &metastorev1alpha1.Line{