Skip to content

pkg/query: Fix nil panic in flamegraph table + top#6337

Open
AlJohri wants to merge 1 commit intoparca-dev:mainfrom
AlJohri:fix-nil-function-flamegraph-table
Open

pkg/query: Fix nil panic in flamegraph table + top#6337
AlJohri wants to merge 1 commit intoparca-dev:mainfrom
AlJohri:fix-nil-function-flamegraph-table

Conversation

@AlJohri
Copy link
Copy Markdown

@AlJohri AlJohri commented Apr 19, 2026

Summary

GenerateFlamegraphTable (flamegraph_table.go) and GenerateTopTable (top.go) both assume that every location.Lines[i].Function is non-nil and panic with

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x477e7c6]

goroutine 551 [running]:
github.com/parca-dev/parca/pkg/query.(*tableConverter).AddFunction(0xc00024e680, 0x0)
    github.com/parca-dev/parca/pkg/query/flamegraph_table.go:312 +0x26
github.com/parca-dev/parca/pkg/query.(*tableConverter).AddProfileLocation(0xc00024e680, 0xc00a90dac0)
    github.com/parca-dev/parca/pkg/query/flamegraph_table.go:284 +0x12f
github.com/parca-dev/parca/pkg/query.GenerateFlamegraphTable(...)
    github.com/parca-dev/parca/pkg/query/flamegraph_table.go:53 +0x79d
...

when a caller passes in an unsymbolized line (Line with no Function reference), which crashes the whole server process.

The same class of bug existed in pkg/query/flamegraph.go and was fixed in #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 and remain on main today.

How to reproduce

I hit this running parca v0.27.1 as the backend for the OpenTelemetry eBPF profiler. Profiles arrive via OTLP; a subset of locations are unsymbolized (no uploaded debuginfo for that build-id yet, or no match in kallsyms), producing Line records with nil Function.

Any of these then crash parca-server:

REPORT_TYPE_FLAMEGRAPH_TABLE
REPORT_TYPE_TOP

REPORT_TYPE_PPROF and REPORT_TYPE_FLAMEGRAPH_ARROW go through different code paths and are unaffected.

Verification

Built a patched image from this branch (based on the v0.27.1 tag), deployed to our cluster, re-ran the same queries that were crashing:

  • REPORT_TYPE_TOP — returns 142 nodes, 127 with resolved function names, no crash.
  • REPORT_TYPE_FLAMEGRAPH_TABLE — returns valid tree (~297 KB payload), parca UI renders the flame graph correctly.
  • Pod uptime since switch: clean (0 restarts vs. ~1 restart / 10 min before).

Existing flamegraph_flat_test.go / top_test.go continue to pass; nil-Line case isn't covered by existing tests — happy to add targeted cases here if that'd help.

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 parca-dev#3892
("Fix nil panic when building flat flamegraph", dd07a12) 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 43cd07b) 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
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 19, 2026

CLA assistant check
All committers have signed the CLA.

@AlJohri AlJohri marked this pull request as ready for review April 19, 2026 21:57
@AlJohri AlJohri requested a review from a team as a code owner April 19, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants