tree-sitter-grammars / tree-sitter-hcl

HCL grammar for tree-sitter
https://tree-sitter-grammars.github.io/tree-sitter-hcl/
Apache License 2.0
92 stars 20 forks source link

Potential fix for #38 #39

Closed amaanq closed 10 months ago

amaanq commented 10 months ago

This doesn't truncate the lengths of the vector and strings when (de)serializing. It might fix the crashes in #38

Also - synced generation w/ upstream cli on master

mhoffm-aiven commented 10 months ago

CI Failure looks unrelated to me ( probably the windows github action needs a bump ). I was able to repro the issue; ill test if this branch fixes it for me in the afternoon!

Thank you

MichaHoffmann commented 10 months ago

Meh, i was hopeful that this would help but

/root/.emacs.d/tree-sitter/libtree-sitter-hcl.so(+0x41049)[0x7fee61ca2049]
/root/.emacs.d/tree-sitter/libtree-sitter-hcl.so(tree_sitter_hcl_external_scanner_deserialize+0x31)[0x7fee61ca33e4]

still fails in deserialization somehow

amaanq commented 10 months ago

would be nice if you could build it in debug mode for a real traceback

MichaHoffmann commented 10 months ago

Is it maybe some issue with emacs using different version of libtreesitter then what we used to generate the parser?

amaanq commented 10 months ago

No that wouldn't be it, at best different versions would do nothing, at worst it would cause a freeze/hang up

MichaHoffmann commented 10 months ago

Ok let me try to patch emacs to build the treesitter library with debug symbols

MichaHoffmann commented 10 months ago
(gdb) bt
#0  0x00007fe7bb7391b5 in __GI___libc_free (mem=0x8) at malloc.c:3344
#1  0x00007fe7b925f049 in deserialize
    (scanner=0x13a0110, buffer=0x14e9750 "\001", length=9) at scanner.c:164
#2  0x00007fe7b92603e4 in tree_sitter_hcl_external_scanner_deserialize
    (payload=0x13a0110, buffer=0x14e9750 "\001", length=9) at scanner.c:402
#3  0x00007fe7bbc6a250 in ts_parser__restore_external_scanner
    (external_token=..., self=0x14d6cb0) at lib/src/parser.c:340
#4  ts_parser__lex (parse_state=437, version=<optimized out>, self=0x14d6cb0)
    at lib/src/parser.c:426
#5  ts_parser__advance
    (allow_node_reuse=<optimized out>, version=0, self=<optimized out>)
    at lib/src/parser.c:1441
#6  ts_parser_parse (self=0x14d6cb0, old_tree=old_tree@entry=0x0, input=...)
    at lib/src/parser.c:1933
#7  0x00000000005ea49d in treesit_ensure_parsed (parser=0x14b8f8d) at treesit.c:1056
#8  Ftreesit_parser_root_node (parser=0x14b8f8d) at treesit.c:1530
MichaHoffmann commented 10 months ago

Something in STRING_FREE seemingly

MichaHoffmann commented 10 months ago

I notice that the similar macros in tree-sitter-bash look slightly different too; i.e. here:

     {                                                                          \
         if ((vec).data != NULL)                                                \
             free((vec).data);                                                  \
+        (vec).data = NULL                                                      \
     }

We were missing the last line; is that maybe not portable?

MichaHoffmann commented 10 months ago

generally the deserialize method of the bash parser looks wildly different too