tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
409 stars 51 forks source link

Avoid undefined behaviour #1

Closed dimbleby closed 2 years ago

dimbleby commented 2 years ago

memcpy() with a null destination or source is undefined.

I realise that this parser is work in progress, but I couldn't resist pointing the fuzzer at it to see what it had to say. This was the first thing that it found; so I thought I'd send you an MR.

The other that I have discovered is that the following file causes an infinite loop:

```

that's three backticks and - importantly - no final new line character (the file contains just three bytes).

Probably it doesn't make much sense for me to be fuzzing this in its current state so I'll stop now. But I'd encourage you to set it up for yourself: it's not so hard and, as above, it'll find bugs!

MDeiml commented 2 years ago

Thank you for your efforts. As you said this is still very much in development and the code is quite a mess atm. Still, fuzzing is something I wanted to setup so this is very helpful. I've never worked with fuzzers before, could you share your setup?

dimbleby commented 2 years ago

I followed the path set out in this comment; though I see that https://github.com/tree-sitter/tree-sitter/blob/master/test/fuzz/README.md is a thing and perhaps better.