tree-sitter / tree-sitter

An incremental parsing system for programming tools
https://tree-sitter.github.io
MIT License
18.62k stars 1.45k forks source link

Crash in fuzzing tests #220

Closed bfredl closed 6 years ago

bfredl commented 6 years ago

When I tried to run the test suite, I got a segfault in the fuzzing-examples.cc tests:

Random seed: 1541343708
............................................................................................................................
Program received signal SIGSEGV, Segmentation fault.
0x00005555556da467 in ts_tree_root_node (self=0x0) at src/runtime/tree.c:34
34        return ts_node_new(self, &self->root, ts_subtree_padding(self->root), 0);
(gdb) bt
#0  0x00005555556da467 in ts_tree_root_node (self=0x0) at src/runtime/tree.c:34
#1  0x00005555556279c0 in assert_consistent_tree_sizes (tree=0x0, 
    text="\006", '-' <repeats 24 times>, "q\212\322-/", '-' <repeats 22 times>, "q\212\322-/", '-' <repeats 14 times>, "1----6--\372Y")
    at test/helpers/tree_helpers.cc:119
#2  0x000055555562b43d in <lambda()>::<lambda()>::<lambda()>::operator()(void) const (__closure=0x7fffffffda80) at test/integration/fuzzing-examples.cc:51

It seems ts_parser_parse_string returns a NULL tree. This happens with both Test/tests and Release/tests.

I run a x86_64 Arch Linux system with GCC version 8.2.1.

maxbrunsfeld commented 6 years ago

It seems ts_parser_parse_string returns a NULL tree.

That often means that the parser doesn't have a language assigned to it, which can happen if one of the test fixture languages javascript or python failed to load or needs to be re-built.

Does it help if you run script/fetch-fixtures again? If not, you can run the tests under a debugger by running script/test -f fuzzing -d. In that test, if you retrieve the language using ts_parser_language, is it null?

bfredl commented 6 years ago

./script/configure; ./script/test fetched a lot of stuff already, I wasn't aware there was an extra step to fetch fixtures. load_real_language shows some debug messages already, perhaps it should show one for missing file?

maxbrunsfeld commented 6 years ago

Yeah, we should add a proper error message for that.

maxbrunsfeld commented 6 years ago

@bfredl Did fetching the fixture grammars resolve the issue for you though?

bfredl commented 6 years ago

Yes, seems to work now.