From cb87b7b76e3ef1b3c624b5cc5fa2484051efc266 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 1 Oct 2019 11:28:49 -0700 Subject: [PATCH] Fix invalid read by query cursor on error nodes :tophat: @bfredl Refs https://github.com/tree-sitter/tree-sitter/pull/448#issuecomment-536337749 --- lib/src/query.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/src/query.c b/lib/src/query.c index 5d240fbe..c6ec3962 100644 --- a/lib/src/query.c +++ b/lib/src/query.c @@ -1006,7 +1006,10 @@ static inline bool ts_query_cursor__advance(TSQueryCursor *self) { &can_have_later_siblings_with_this_field ); TSNode node = ts_tree_cursor_current_node(&self->cursor); - TSSymbol symbol = self->query->symbol_map[ts_node_symbol(node)]; + TSSymbol symbol = ts_node_symbol(node); + if (symbol != ts_builtin_sym_error) { + symbol = self->query->symbol_map[symbol]; + } // If this node is before the selected range, then avoid descending // into it.