Skip to content

LSP crashes with SIGSEGV when processing service definitions (protocompile v0.14.2) #4192

@Okxdd123

Description

@Okxdd123

Buf LSP Server Crashes with SIGSEGV when Processing Service Definitions

Environment

  • Buf Version: 1.61.0
  • OS: macOS 26.2 (Build 25C5048a)
  • VS Code Version: 1.106.2
  • Architecture: arm64
  • protocompile Version: v0.14.2-0.20251120233202-3f9009bcd6c8

Description

The Buf LSP server crashes with a segmentation fault (SIGSEGV) when opening a .proto file containing a service definition. The crash occurs consistently and prevents the LSP from functioning.

Error Message

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1016ed1fc]

goroutine 49 [running]:
github.com/bufbuild/protocompile/experimental/ir.MessageValue.Field({{{0x0?}, 0x0?, 0x55419a?}}, {{{0x0?}, 0x0?, 0x0?}})
    github.com/bufbuild/[email protected]/experimental/ir/ir_value.go:793 +0xcc
github.com/bufbuild/protocompile/experimental/ir.Service.Deprecated({{{0x14002d09b08?}, 0x140031a7188?, 0x1aa?}})
    github.com/bufbuild/[email protected]/experimental/ir/ir_service.go:111 +0x7c
github.com/bufbuild/protocompile/experimental/ir.Symbol.Deprecated({{{0x14002d09b08?}, 0x14002fa28d0?, 0x1b7b380?}})
    github.com/bufbuild/[email protected]/experimental/ir/ir_symbol.go:144 +0xc4
github.com/bufbuild/buf/private/buf/buflsp.(*symbol).GetSymbolInformation(0x14004e6c900)
    github.com/bufbuild/buf/private/buf/buflsp/symbol.go:297 +0x148
github.com/bufbuild/buf/private/buf/buflsp.(*server).DocumentSymbol.(*file).GetSymbols.func1(...)
    github.com/bufbuild/buf/private/buf/buflsp/file.go:991
github.com/bufbuild/buf/private/buf/buflsp.(*server).DocumentSymbol(0x1400006ae40?, {0x101cb2960?, 0x140052e6aa0?}, 0x1016a3db4?)
    github.com/bufbuild/buf/private/buf/buflsp/server.go:553 +0x138

Root Cause

The crash occurs in ir.Service.Deprecated() when it attempts to access the deprecated option of a service through MessageValue.Field(). The issue is that the MessageValue is nil, but the code doesn't perform a nil check before dereferencing.

The crash happens during the DocumentSymbol request, specifically when the LSP tries to extract symbol information including the deprecated status.

Steps to Reproduce

  1. Create a .proto file with the following content:
syntax = "proto3";

package api.mb_tenant_news.v1.timeline;

import "google/protobuf/timestamp.proto";
import "buf/validate/validate.proto";

option go_package = "example.com/api/timeline;timeline";

// Timeline service
service Timeline {
  rpc ListTimeline(ListTimelineRequest) returns (ListTimelineResponse);
}

message ListTimelineRequest {
  string title = 1;
}

message ListTimelineResponse {
  repeated string items = 1;
}
  1. Open the file in VS Code with Buf LSP enabled
  2. The LSP crashes immediately with SIGSEGV

Expected Behavior

The LSP should handle services without explicit deprecated options gracefully and not crash.

Actual Behavior

The LSP crashes with a nil pointer dereference when trying to access the service's options.

Workarounds Attempted

  1. Adding option deprecated = false; to the service - Still crashes
  2. Setting BUF_BETA_SUPPRESS_WARNINGS=1 - Still crashes
  3. Disabling Buf LSP - Works but loses LSP functionality

Analysis

Looking at the stack trace:

  • ir_service.go:111 calls Service.Deprecated()
  • This internally calls MessageValue.Field() at ir_value.go:793
  • The MessageValue is nil, causing the panic

The code should either:

  1. Check if the MessageValue is nil before calling .Field()
  2. Return a default value (false) when options are not present
  3. Properly initialize the MessageValue for services without options

Minimal Reproducible Example

I can provide the complete proto files if needed. The issue occurs with any service definition, regardless of whether it has options or not.

Additional Context

  • The proto files are syntactically correct and compile successfully with protoc
  • The issue appeared after updating to buf v1.61.0
  • This affects all proto files with service definitions in our workspace
  • The LSP crashes 5 times in 3 minutes and then stops restarting

Proposed Fix

In github.com/bufbuild/protocompile/experimental/ir/ir_service.go:111, the Deprecated() method should check if the service options MessageValue is nil before attempting to access fields:

func (s Service) Deprecated() bool {
    opts := s.Options()
    if opts.IsZero() {  // Add nil/zero check
        return false
    }
    // ... existing code
}

Impact: This bug prevents the LSP from working entirely, breaking developer productivity for anyone using service definitions in their proto files.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions