Skip to content

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

Closed

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):

  • 064a6130 — fix(ts-runtime): bound GLR stack merge recursion to prevent Windows stack overflow
  • 560f70a1 — test(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

  1. added
    bugSomething isn't working
    stability/performanceServer crashes, OOM, hangs, high CPU/memory
    priority/normalStandard review queue; useful PR with ordinary maintainer urgency.
    on Jul 7, 2026
  2. DeusData commented on Jul 7, 2026

    @DeusData
    Owner

    Thanks for splitting this out from the Perl PR. Triage: vendored runtime hardening bug, normal priority.

    A tree-sitter runtime patch needs separate provenance and risk review, as noted earlier. The acceptable shape is a narrow recursion cap with graceful degradation plus a crash-isolating regression, with no unrelated runtime behavior changes.

  3. added this to the 0.9.1-rc milestone on Jul 8, 2026
  4. DeusData commented on Jul 11, 2026

    @DeusData
    Owner

    Yes please — open the PR against main. This is exactly the right split: vendored-runtime patches deserve their own review. Process notes for ts_runtime changes: (1) keep it reproduce-first — the fork-harness deep-nesting test should be RED (stack overflow contained via the harness) before the depth bound lands, so the guard provably catches the crash class; (2) document the local modification in the vendored runtime's provenance notes (same spirit as the grammar MANIFEST — we track every divergence from upstream so a future runtime upgrade doesn't silently drop it); (3) note the upstream tree-sitter issue/PR if one exists so we can retire the patch when upstreaming catches up. Milestone 0.9.1-rc. Looking forward to it — the bounded-merge degradation (no incorrect parse) is the right call.

  5. added
    awaiting-reporterWaiting on the reporter for info/repro; stale bot will warn then close
    on Jul 11, 2026
  6. github-actions commented on Jul 11, 2026

    @github-actions

    Thanks for the report! To move this forward we need a bit more so we can reproduce it ourselves:

    • the codebase-memory-mcp --version you're on
    • the exact steps or command you ran
    • a public repo (or a small dummy snippet) that shows the problem — please don't paste proprietary code

    Once that's here we'll pick it straight back up. Heads-up: issues left awaiting-reporter are automatically closed after a few weeks of silence, but a comment reopens the door anytime.

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