Skip to content

heap-use-after-free: cross-suite thread-slab vs tree-sitter teardown (test-runner pipeline mem) #852

Closed

Description

@DeusData

Found during the keystone memory PR build (2026-07-04), proven pre-existing (reproduces with that PR's mem.c change reverted; none of its files are in the faulting path).

Repro: ./build/c/test-runner pipeline mem (ASan build). Each suite passes ALONE; the UAF only fires in this cross-suite ordering.

Fault: heap-use-after-free — ts_lexer_goto (vendored tree-sitter lexer.c:150) reads memory freed by cbm_slab_destroy_thread (slab_alloc.c:219), originating from test_mem.c:662 slab_tier1_malloc_backed. Looks like a thread-local slab is destroyed while a tree-sitter parser/lexer from a prior suite still references slab-backed memory — a teardown-ordering / lifetime bug between the custom thread-slab allocator and tree-sitter's parser state.

Reproduce-first TODO: isolate into a minimal RED test (one slab-backed parse + thread-slab destroy while the tree/lexer is still live) rather than relying on suite ordering; then fix the teardown ordering (destroy parsers before the thread slab, or detach slab-backed buffers). Memory-safety bug → priority/high.

Activity

  1. added
    bugSomething isn't working
    stability/performanceServer crashes, OOM, hangs, high CPU/memory
    priority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.
    on Jul 4, 2026
  2. added a commit that references this issue on Jul 4, 2026
    74b27f3
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

    bugSomething isn't workingpriority/highNeeds near-term maintainer attention; high-impact bug, regression, safety issue, or release blocker.stability/performanceServer crashes, OOM, hangs, high CPU/memory

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions