tree-sitter-sql: segfault

Hi

somewhere between 44e36038f032eff2f36522642a8cc4351e133f83 ( good ) and 764c1bd5ea856dd7db5171783e442321dc3e041f (bad) segfault when opening sql file.

unfortunately I can not post sql file here ( prod code )

I am not familiar enough with tree-sitter, whats the easiest way to run parser though any sql file ?

I’ve tried adding offending sql file to test/highlight but that did’t do anything

syntax highlighting:
  ✓ union.sql (13 assertions)
  ✓ query.sql (14 assertions)
  ✓ structure.sql (0 assertions) <--- this is the file that causes segfault in neovim

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 16 (1 by maintainers)

Most upvoted comments

I investigated around this issue a little bit, i’m quit sure about it but it might be tree-sitter issue as it turns out returning ‘$$’ if we add a return "$$" before this line: https://github.com/DerekStride/tree-sitter-sql/blob/b24e6759c0c05875b4929cc868bb6494ff797b83/src/scanner.c#L71 buffer overflow can be reproduced with fortify3 without involvement of any strcpy usage. and gdb references the overflow from tree-sitter itself so the chances that it’s a not related to scanner is pretty high

using state of art binary search, here is minimal snipplet that causes segfault ( within nixpkgs), but doesn’t segfault run tree-sitter parse

CREATE FUNCTION public.foo() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
END;
$$;

the issue is as $$, when I change it to as bar it works