emacs-tree-sitter / elisp-tree-sitter

Emacs Lisp bindings for tree-sitter
https://emacs-tree-sitter.github.io
MIT License
827 stars 74 forks source link

Crash when loading one particular Markdown file #253

Open autarch opened 1 year ago

autarch commented 1 year ago

I've seen this crash in both Emacs 27 & 28, with the packages tree-sitter@3cfab8a0e945db9b3df84437f27945746a43cc71 and tree-sitter-langs@d8f8ac4faeb4564fbb61e94a631b4672523d84a9

If I run emacs --debug from the CLI I see this when it crashes:

emacs: src/./tree_sitter_markdown/inline_delimiter.cc:240: void tree_sitter_markdown::InlineDelimiterList::transfer_to(tree_sitter_markdown::MinimizedInlineDelimiterList&): Assertion `inl_dlm.sym() == SYM_EXT_AUT_LNK_BGN || inl_dlm.sym() == SYM_EXT_AUT_LNK_CTN' failed.
Fatal error 6: Aborted
Backtrace:
emacs[0x530972]
emacs[0x426a12]
emacs[0x426efc]
emacs[0x52eecd]
emacs[0x52efbf]

/lib/x86_64-linux-gnu/libpthread.so.0(+0x14420)[0x7ff37667d420]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcb)[0x7ff37630f00b]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x12b)[0x7ff3762ee859]
/lib/x86_64-linux-gnu/libc.so.6(+0x22729)[0x7ff3762ee729]
/lib/x86_64-linux-gnu/libc.so.6(+0x33fd6)[0x7ff3762fffd6]
/home/autarch/.emacs.d/elpa/tree-sitter-langs-20230205.2032/bin/markdown.so(_ZN20tree_sitter_markdown19InlineDelimiterList11transfer_toERNS_28MinimizedInlineDelimiterListE+0x16e)[0x7ff369171c9e]
/home/autarch/.emacs.d/elpa/tree-sitter-langs-20230205.2032/bin/markdown.so(tree_sitter_markdown_external_scanner_scan+0x841)[0x7ff3691afb51]
/home/autarch/.emacs.d/elpa/tsc-20220212.1632/tsc-dyn.so(+0x14da92)[0x7ff36a6afa92]
/home/autarch/.emacs.d/elpa/tsc-20220212.1632/tsc-dyn.so(+0x12d0d1)[0x7ff36a68f0d1]
/home/autarch/.emacs.d/elpa/tsc-20220212.1632/tsc-dyn.so(+0x128a6a)[0x7ff36a68aa6a]
/home/autarch/.emacs.d/elpa/tsc-20220212.1632/tsc-dyn.so(+0x12d526)[0x7ff36a68f526]
emacs[0x5c5036]
emacs[0x595297]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x59534d]
emacs[0x5949ed]
emacs[0x594b63]
emacs[0x595333]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x5d4184]
emacs[0x595297]
emacs[0x5d4184]
...
Aborted (core dumped)

The file in question is attached to this issue.

README.md

kassick commented 1 year ago

Another offending file README.md

sogaiu commented 1 year ago

For the sample in this comment, here tree-sitter parse yields:

tree-sitter: /tmp/tree-sitter-markdown.ikatyang/src/./tree_sitter_markdown/inline_delimiter.cc:240: void tree_sitter_markdown::InlineDelimiterList::transfer_to(tree_sitter_markdown::MinimizedInlineDelimiterList&): Assertion `inl_dlm.sym() == SYM_EXT_AUT_LNK_BGN || inl_dlm.sym() == SYM_EXT_AUT_LNK_CTN' failed.
Aborted (core dumped)

For the sample in this comment, here tree-sitter parse yields:

tree-sitter: /tmp/tree-sitter-markdown.ikatyang/src/./tree_sitter_markdown/inline_delimiter.cc:240: void tree_sitter_markdown::InlineDelimiterList::transfer_to(tree_sitter_markdown::MinimizedInlineDelimiterList&): Assertion `inl_dlm.sym() == SYM_EXT_AUT_LNK_BGN || inl_dlm.sym() == SYM_EXT_AUT_LNK_CTN' failed.
Aborted (core dumped)

Output looks the same to me, though the input files appear to differ.

This is using ikatyang's markdown grammar at commit 8b8b77af and the tree-sitter cli commit is 524bf7e2.

kassick commented 1 year ago

It appears to be caused by table-long dash-lines in tables -- this example crashes emacs with the following backtrace (using the version available at commit 69fa82c76fc25b30fc0528291423002dd18a89e5 of elisp-tree-sitter

As the assertion seems to come from https://github.com/ikatyang/tree-sitter-markdown/, it probably requires a fix there. It does not seem to be related to https://github.com/ikatyang/tree-sitter-markdown/issues/59 or https://github.com/ikatyang/tree-sitter-markdown/issues/57, I'll open a new issue there.

emacs: src/./tree_sitter_markdown/inline_delimiter.cc:240: void tree_sitter_markdown::InlineDelimiterList::transfer_to(tree_sitter_markdown::MinimizedInlineDelimiterList&): Assertiva “inl_dlm.sym() == SYM_EXT_AUT_LNK_BGN || inl_dlm.sym() == SYM_EXT_AUT_LNK_CTN” falhou.
Fatal error 6: Aborted
Backtrace:
emacs[0x52d3ab]
emacs[0x4222ff]
emacs[0x422801]
emacs[0x52ba08]
emacs[0x52bae9]
/lib64/libc.so.6(+0x3db70)[0x7fc622290b70]
/lib64/libc.so.6(+0x8e844)[0x7fc6222e1844]
/lib64/libc.so.6(gsignal+0x1e)[0x7fc622290abe]
/lib64/libc.so.6(abort+0xdf)[0x7fc62227987f]
/lib64/libc.so.6(+0x2679b)[0x7fc62227979b]
/lib64/libc.so.6(+0x36147)[0x7fc622289147]
/home/kassick/.emacs.d/elpa/29.1/develop/tree-sitter-langs-20230910.547/bin/markdown.so(_ZN20tree_sitter_markdown19InlineDelimiterList11transfer_toERNS_28MinimizedInlineDelimiterListE+0x16e)[0x7fc5b06e0c9e]
/home/kassick/.emacs.d/elpa/29.1/develop/tree-sitter-langs-20230910.547/bin/markdown.so(tree_sitter_markdown_external_scanner_scan+0x841)[0x7fc5b071eb51]
/home/kassick/.emacs.d/elpa/29.1/develop/tsc-20230916.113114/tsc-dyn.so(+0x14da92)[0x7fc5c614da92]
/home/kassick/.emacs.d/elpa/29.1/develop/tsc-20230916.113114/tsc-dyn.so(+0x12d0d1)[0x7fc5c612d0d1]
/home/kassick/.emacs.d/elpa/29.1/develop/tsc-20230916.113114/tsc-dyn.so(+0x128a6a)[0x7fc5c6128a6a]
/home/kassick/.emacs.d/elpa/29.1/develop/tsc-20230916.113114/tsc-dyn.so(+0x12d526)[0x7fc5c612d526]
emacs[0x5d2172]
emacs[0x5e148e]
emacs[0x5994e6]
emacs[0x5995a9]
emacs[0x59841c]
emacs[0x598629]
emacs[0x5994e6]
/usr/local/bin/../lib/emacs/29.1.50/native-lisp/29.1.50-a92a42e2/preloaded/subr-13adf6a6-8f3898dc.eln(F72756e2d6d6f64652d686f6f6b73_run_mode_hooks_0+0x389)[0x7fc61f65fd09]
emacs[0x5994e6]
/usr/local/bin/../lib/emacs/29.1.50/native-lisp/29.1.50-a92a42e2/preloaded/elisp-mode-90dbfe40-2f48c113.eln(F656d6163732d6c6973702d6d6f6465_emacs_lisp_mode_0+0x62c)[0x7fc61f246a7c]
emacs[0x5e1450]
emacs[0x5e3c8b]
emacs[0x59d020]
emacs[0x59d5d8]
emacs[0x59cf07]
emacs[0x59f4d6]
/home/kassick/.emacs.d/eln-cache/29.1.50-a92a42e2/yasnippet-1427ec8a-8df7bbfb.eln(top_level_run+0xaf58)[0x7fc5b080c6c3]
emacs[0x5ec8e8]
emacs[0x5ecd73]
emacs[0x5cb863]
emacs[0x5cc0b8]
emacs[0x5991c1]
emacs[0x59b5a2]
emacs[0x59c975]
...
sogaiu commented 1 year ago

The following extract from the first sample was enough to cause the error for me:

| Key       | Type             | Required? | Description                                                                                                                                                                                                                                                                                                                                                                                                              |
| --------- | ---------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `exclude` | array of strings | no        | Each array member is a pattern that will be matched against potential files when `precious` is run. These patterns are matched in the same way as patterns in a [gitignore file](https://git-scm.com/docs/gitignore#_pattern_format). 
You can use lines starting with a `!` to negate the meaning of previous rules in the list, so that anything that matches is _not_ excluded even if it matches previous rules. |
autarch commented 1 year ago

Thanks for digging into this and reporting it to the right place. Does it make sense to leave this issue open until upstream fixes it? I'm assuming that elisp-tree-sitter would need to update the version of tree-sitter-markdown it pulls in.

sogaiu commented 1 year ago

Leaving the issue open seems good to me.

aguynamedben commented 1 year ago

I see this on Emacs 30.0.5 using tree-sitter with https://github.com/ikatyang/tree-sitter-markdown and my crash is also on tables. I'm using the built-in tree-sitter in Emacs 30, not this library directly, but this issue is the best place with examples + root cause, so tossing my example README file in here:

image