-
-
Notifications
You must be signed in to change notification settings - Fork 830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing pug
in vue
file causes segmentation fault
#2360
Comments
@zealot128 since the injection causes that problem I suppose the scanner of the pug parser could be the problem. Could you check that using gdb? You could also try to build the parser using debug symbols |
I don't know if it's related, but this started failing for me the same day |
Having the same issue lately. Can also confirm the same with bat as @tshakah noted. I'm not really well versed in debugging things like this.
I'll gladly provide more information with a little guidance on how to proceed! |
@tshakah syntect is really a completely different technology that is not used by tree-sitter |
I investigated this a bit more with git bisect. This only happens with nvim starting with commit neovim/neovim@45f7fc9, v0.6.1 doesn't show this problem. I made a simple Dockerfile that reproduces the issue: https://github.com/strayer/nvim-treesitter-2360 Should be pretty easy to get gdb going in there, but I don't really know how to provide more info with that as I mentioned earlier. Maybe helpful gdb output:
|
Vue crashes nvim - nvim-treesitter/nvim-treesitter#2360
@zealot128 the pug parser used here is https://github.com/zealot128/tree-sitter-pug and we've been talking before, so I hope you don't mind me tagging you here. Sadly you have disabled issues on the repo, so I can't open one there. Do you have any idea what might be wrong here? |
That repo has no issues enabled because it is just a fork from https://github.com/RianFuro/tree-sitter-pug which I found, forked and enhanced the parser grammar. Also, Pug parser.c just uses some "lexer->get_column" which seems to be relevant for the stacktrace. But lexer is an external object, which is not defined in the treesitter-pug file. |
I'm primarily using a Macbook with an i9 on Monterey, but the example Dockerfile above would be running in Docker for Mac, so Linux amd64. The Dockerfile is based on Debian Bullseye. As far as I recall this is NOT happening on neovim 0.6.1, so the latest stable release should not show this problem. I updated the Dockerfile to run gdb so it is easy to test the segfault. At least on my side it is 100% reproducible. Ref: https://github.com/strayer/nvim-treesitter-2360 Edit: Oh well, even with neovim 0.6.1 installed via Homebrew this happens, so it isn't limited to neovim master builds. This only applies to macOS though, uncommenting the 0.6.1 tag checkout in the Dockerfile doesn't show the problem and runs fine. |
mhm After upgrading do HEAD (NVIM v0.8.0-dev), I also now can confirm a SegFault when opening Vue files with PUG lang :( Trying to install from Grammar gives me:
Downgrading tree-sitter-cli to 0.20.4 works. Installting latest 0.20.6 results in the error above though... Because Ubuntu 18 only has Glib 2.27, it's nothing I can test here in our environment. :( Sorry, I have not much experience with the whole C-build-system, Maybe this is also the issue in the problem above; mismatch of Glibc versions? |
@zealot128 are you using neovim on a platform like snap, appimage or flatpak that could use a different C runtime than your system compiler? |
@theHamsta I use Ubuntu 18.04 with a "unstable" ppa:
no Flatpak snap etc.; I only work on a remote Ubuntu server and we are still using Deb's for most stuff. Downgrading to "stable" = 0.6.1 works. Then no Segfault and working Pug highlighting
|
indicates that the binary installation of tree-sitter does not work with your OS. Can you remove the node installation of tree-sitter and try |
since the problem is happening in Fuzzing confirms that tree-sitter-pug can segfault (even though the cause may be different). If the SEGFAULTs don't get fixed in tree-sitter-pug, we probably have to remove that parser
|
@zealot128 ooops wrong parser (RianFuro/tree-sitter-pug)... let me try yours... |
I hope that I this time used your parser. It gives a test case at the end. I recommend to use the tool by yourself to check whether your parser doesn't crash on fuzzing (how to set up: ikatyang/tree-sitter-markdown#14). Script assumes that
|
@theHamsta thank you for the info. I didn't modify the parser/lexer at all, but only forked the original repo and modified the grammar.js + test cases, which worked so far. The Segfault would then be already present in the original repo. I didn't wrote the C++ code there, so I am a little out of my comfort zone looking at the parser's Cpp-code. The function you've mentioned just casts the instance to Scanner and calls an instance method, which then does the space counting, maybe originally from the Python-Treesitter, if I enter some code fragments here on the Github code search. I tried to just use the Ubuntu packaged libfuzzer, but it also seems to be too old: $ sudo apt install libfuzzer-10-dev
$ git clone https://github.com/tree-sitter/tree-sitter; cd tree-sitter
$ ln -s ../tree-sitter-pug ./test/fixtures/grammars/pug
$ mkdir out
# File exists: libFuzzer.a!
$ export LIB_FUZZER_PATH=/usr/lib/llvm-12/lib/libFuzzer.a
$ ./script/build-fuzzers
cc -fsanitize=fuzzer,address,undefined -std=gnu99 -fPIC -Ilib/src -Ilib/include -c -o lib/src/tree_cursor.o lib/src/tree_cursor.c
cc: error: unrecognized argument to -fsanitize= option: ‘fuzzer’
<builtin>: recipe for target 'lib/src/tree_cursor.o' failed
make: *** [lib/src/tree_cursor.o] Error 1 With my current system I also can not run the cargo install tree-sitter-cli, too, as the tree-sitter-cli seems toe require a newer Rust version. Did your test run produces a bogus input file for test? |
@zealot128 probably you have to use clang. The error at pointer 0x000000000002 indicates that some of the variables is a nullptr. Maybe a check for that would be sufficient. |
Maybe it's also about the vector that has never been allocated. This could also require to look up a nullptr at a uint16_t offset. Using a debugger and compling the parser in debug mode could help |
This line is very suspicious https://github.com/zealot128/tree-sitter-pug/blob/5875f9a7d94836708119b0a1102bb5792e8bf673/src/scanner.cc#L37 when indent_length_stack is empty |
@zealot128 You're completely right, I basically just started with the python scanner as a template and ripped out what I felt I won't need and to help me try to understand what's actually going on. I'm not that good with the C-Family either, so this was very much a "tinker till it works" effort from my side. So I have to apologize, I won't be of much help either sadly 😓 For reference, I used this version as a template: https://github.com/tree-sitter/tree-sitter-python/blob/87e874f23e1bbfc4bd160caa3bad03de250c8b9f/src/scanner.cc |
Thanks to @theHamsta's PR it now worked for me on Neovim 0.7 with the latest pug. At least in cursory glance most highlighting worked. But the changes made half of the treesitter-pug test fail, so we have to investigate if this is relevant or just implementation specific. |
But the SEGFAULT is solved so I guess we can close the issue here. |
The segmentation fault problem is solved. I close this issue. Thank you! |
Describe the bug
Neovim crashes itself by
segmentation fault
when opening avue
file containing<template lang="pug">
.This problem seems to be occurring after this commit: dec2ba2
To Reproduce
Open the file below after
:TSInstall vue
Expected behavior
Open the file successfully.
Output of
:checkhealth nvim-treesitter
Output of
nvim --version
Additional context
No response
The text was updated successfully, but these errors were encountered: