Skip to content

internal/driver: guard BuildID slice in locateBinaries to prevent panic on short BuildID#998

Merged
aalexand merged 1 commit into
google:mainfrom
evilgensec:fix/buildid-slice-bounds-panic
May 7, 2026
Merged

internal/driver: guard BuildID slice in locateBinaries to prevent panic on short BuildID#998
aalexand merged 1 commit into
google:mainfrom
evilgensec:fix/buildid-slice-bounds-panic

Conversation

@evilgensec
Copy link
Copy Markdown
Contributor

Summary

locateBinaries in internal/driver/fetch.go constructs an LLVM debug-file path by slicing m.BuildID[:2] and m.BuildID[2:] (line 433). The guard at line 424 only checks m.BuildID != "", so a BuildID with fewer than two characters passes the check and causes a panic:

runtime error: slice bounds out of range [:2] with length 1

The profile.proto format places no minimum length requirement on the build_id field, and profile.CheckValid() does not validate it. A crafted profile file with build_id = "X" (or any single-byte value) reliably panics any process that calls locateBinaries.

Impact

Any tool or server that accepts a user-supplied profile and analyzes it (symbolization, flamegraph rendering, etc.) can be crashed by this one-byte build_id. This includes:

  • The standalone pprof binary run by an operator against an untrusted profile
  • Any service that wraps pprof as a library and accepts uploaded profiles

Fix

Add len(m.BuildID) >= 2 guard before the LLVM path construction. This matches the documented precondition of the LLVM build-id convention ("the first two characters are used as the directory name").

Test

Added BuildID: "X" case to TestSymbolizationPath — this panicked before the fix and passes after.

…values

The LLVM debug-file lookup sliced m.BuildID[:2] and m.BuildID[2:] to
construct a filesystem path of the form <path>/<first2>/<rest>.debug.
The existing guard only checked m.BuildID != "", so a BuildID with
fewer than two characters (e.g. a single byte) caused a panic:
  runtime error: slice bounds out of range [:2] with length 1

The profile.proto format imposes no minimum length on BuildID, and the
profile.CheckValid() function does not validate it either. A crafted
profile with a one-character BuildID therefore reliably crashes any
process that calls locateBinaries, including tools or servers that
accept and analyze user-supplied profiles.

Fix: wrap the LLVM path construction in a len(m.BuildID) >= 2 guard,
matching the documented precondition of the LLVM build-id protocol
('the first two characters are used as directory').

Add a test case with BuildID="X" to TestSymbolizationPath to prevent
regression.
@aalexand aalexand enabled auto-merge (squash) May 7, 2026 01:27
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.59%. Comparing base (545e8a4) to head (7497371).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #998      +/-   ##
==========================================
+ Coverage   70.46%   72.59%   +2.12%     
==========================================
  Files          44       44              
  Lines        9877     7793    -2084     
==========================================
- Hits         6960     5657    -1303     
+ Misses       2893     2112     -781     
  Partials       24       24              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aalexand aalexand merged commit 92041b7 into google:main May 7, 2026
50 checks passed
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.

3 participants