Skip to content

ts_runtime: bound GLR stack-merge recursion to prevent stack overflow on pathological input #913

Description

@halindrome

Split out of #461 at maintainer request: patches to the vendored tree-sitter runtime (internal/cbm/vendored/ts_runtime/) warrant a separate decision from ordinary language-extraction code, so filing this independently.

Problem

The GLR stack-merge in internal/cbm/vendored/ts_runtime/src/stack.c recurses without a depth bound. On deeply / pathologically nested input the recursive merge can overflow the native stack — most likely on Windows, where the default thread stack is smallest.

Proposed fix

Bound the GLR stack-merge recursion depth, degrading gracefully past the cap (bounded merge — no incorrect parse), plus a tests/test_stack_overflow.c regression that uses a fork harness to isolate the crash from the rest of the suite.

Prepared commits on halindrome/codebase-memory-mcp (branch perl-lsp-semantic-resolution, pre-cleanup history):

  • 064a6130fix(ts-runtime): bound GLR stack merge recursion to prevent Windows stack overflow
  • 560f70a1test(perl-lsp): use fork harness for deep-nesting test to avoid thread-local parser leak

Provenance

Self-contained depth guard in the vendored runtime; no upstream-grammar regeneration involved. Happy to open a PR against whatever branch / process you prefer for runtime patches.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting-reporterWaiting on the reporter for info/repro; stale bot will warn then closebugSomething isn't workingpriority/normalStandard review queue; useful PR with ordinary maintainer urgency.stability/performanceServer crashes, OOM, hangs, high CPU/memory

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions