Skip to content

Segfaults parsing Solidity, Rust, and TypeScript files #62

Description

@chrispyspearbit

Trailmark 0.4.0 segfaults/SIGBUS while parsing realistic Solidity, Rust, and TypeScript files. This appears related to #61, but it is not limited to Go.

I can reproduce on:

  • macOS ARM64 via uvx --from trailmark python
  • Linux via python:3.12-slim Docker

Environment from Linux repro:

trailmark 0.4.0
python:3.12-slim
tree-sitter 0.26.0
tree-sitter-language-pack 1.12.1

Minimal public-file repro:

docker run --rm -it python:3.12-slim sh -lc '
  apt-get update >/dev/null &&
  apt-get install -y git >/dev/null &&
  pip install -q trailmark &&
  git clone --depth 1 https://github.com/uniswap/v3-core.git /tmp/v3-core &&
  cd /tmp/v3-core &&
  python -X faulthandler - <<PY
from trailmark.parse import parse_file

f = "contracts/libraries/Oracle.sol"
print("parse", f, flush=True)
g = parse_file(f, language="solidity")
print(len(g.nodes), len(g.edges))
PY
'

Observed:

parse contracts/libraries/Oracle.sol
Fatal Python error: Segmentation fault

Current thread ...:
  File "/usr/local/lib/python3.12/site-packages/trailmark/parsers/_common.py", line 33 in node_text
  File "/usr/local/lib/python3.12/site-packages/trailmark/parsers/solidity/parser.py", line 364 in _extract_docstring
  File "/usr/local/lib/python3.12/site-packages/trailmark/parsers/solidity/parser.py", line 130 in _extract_contract
  File "/usr/local/lib/python3.12/site-packages/trailmark/parsers/solidity/parser.py", line 106 in _visit_top_level
  File "/usr/local/lib/python3.12/site-packages/trailmark/parsers/solidity/parser.py", line 95 in _visit_module
  File "/usr/local/lib/python3.12/site-packages/trailmark/parsers/solidity/parser.py", line 73 in parse_file
  File "/usr/local/lib/python3.12/site-packages/trailmark/parse.py", line 105 in parse_file
Segmentation fault

I also reproduced crashes on these public files:

Solidity:
- https://github.com/ValantisLabs/valantis-stex/blob/27b5c748db73d5b5e7d7aeaee902b70c2b74a829/src/STEXAMM.sol
- https://github.com/chronicleprotocol/scribe/blob/a5e0da3a498cb5883502a8fe05e16096254ec3ab/src/Scribe.sol
- https://github.com/uniswap/v3-core/blob/d0831dc6b8a318df3872b6d68f6de135c9f3ec29/contracts/UniswapV3Pool.sol

TypeScript:
- https://github.com/uniswap/v3-core/blob/d0831dc6b8a318df3872b6d68f6de135c9f3ec29/test/Oracle.spec.ts

Rust:
- https://github.com/base/base/blob/6ee3da6325e7416812065c58358274a086f9f223/actions/harness/src/batcher/actor.rs

Notes:

  • Tiny synthetic Solidity/Rust/TypeScript files parse successfully and produce calls edges.
  • The full files above crash reliably.
  • Running one file per subprocess avoids losing the whole batch, but the crashing files still cannot be extracted.
  • On the Solidity repros, faulthandler usually points to node_text or nearby AST child iteration inside the Solidity parser.

Expected:

Trailmark should either parse these files or return a Python-level parse/extraction error. It should not terminate the process via SIGSEGV/SIGBUS.

Metadata

Metadata

Assignees

No one assigned

    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