Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Segmentation Fault in node_get_text #308

Closed
MichaelBreitung opened this issue Oct 24, 2024 · 1 comment · Fixed by #309
Closed

Segmentation Fault in node_get_text #308

MichaelBreitung opened this issue Oct 24, 2024 · 1 comment · Fixed by #309
Labels
bug Something isn't working

Comments

@MichaelBreitung
Copy link

I found a Segmentation Fault in the Tree Sitter Python bindings, which can happen with complex Queries. A python example to reproduce the error is attached here.

Dependencies

tree-sitter==0.23.1
tree-sitter-cpp==0.23.1

Precondition

Install dependencies - requirements.txt is contained in zip

Reproduce

Run python3 main.py from the zip

Error

Running a complex Query with Alternations and Predicates results in a segmentation fault in the Python Bindings.

I am aware now, that the problematic predicate is redundant and I have since removed it from my final program. But it should not produce a segmentation fault. You can test, by removing and adding the predicate at line 18 in my test program (@name (#eq? @name @class_names)) to see the difference.

The core dump suggests a self Null Pointer at node_get_text line 515 in "node.c", called from satisfies_eq_captures line 74 in "query_predicates.c". The first parameter passed in this call is null:

text1 = node_get_text((Node *)PyList_GetItem(nodes1, i), NULL);

I didn't yet dive deeper and check why PyList_GetItem could return a null pointer here and if there should be a check somewhere.

Here's a excerpt of the Core Dump:

#0  0x0000781e4c75d0a8 in node_get_text (self=0x0, _unused_payload=_unused_payload@entry=0x0) at tree_sitter/binding/node.c:515
#1  0x0000781e4c761dad in satisfies_eq_capture (tree=0x781e4c923e40, match=<synthetic pointer>, predicate=0x781e4c821590, state=0x781e4c93e080) at tree_sitter/binding/query_predicates.c:74
#2  query_satisfies_predicates (query=query@entry=0x781e4c949e30, match=..., tree=0x781e4c923e40, callable=0x0) at tree_sitter/binding/query_predicates.c:139
#3  0x0000781e4c761292 in query_captures (self=0x781e4c949e30, args=<optimized out>, kwargs=<optimized out>) at tree_sitter/binding/query.c:558
@MichaelBreitung
Copy link
Author

Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants