gwenn / lemon-rs

LALR(1) parser generator for Rust based on Lemon + SQL parser
The Unlicense
48 stars 10 forks source link

Panic on missing join clause #43

Closed MarinPostma closed 5 months ago

MarinPostma commented 5 months ago

I've been fuzzing the parser and fixed a common cause of panic in https://github.com/tursodatabase/libsql/pull/1209

If the fix suits you, open a PR here.

gwenn commented 5 months ago

10

gwenn commented 5 months ago

If you are interested, you should be able to generate more crash tests by patching this with: (you can try first without the patch to check many valid SQLite commands)

misc % diff -u test-grammar.pegjs*
--- test-grammar.pegjs  2024-02-26 20:00:37.000000000 +0100
+++ test-grammar.pegjs.bk   2024-02-26 20:00:06.000000000 +0100
@@ -42,7 +42,8 @@
     return b;
   }
 test_type_start
-  = "do_execsql_test"
+  = "do_catchsql_test"
+  / "do_execsql_test"
   / "do_eqp_test"
   / "execsql"
   / "eqp"

Create a symlink to a local clone of official SQLite3 repository:

% cd sqlite-parser/test
% ln -s ~/sqlite/test raw

Launch

% cd sqlite-parser/test/misc
% sh process-tests.sh

And then with lemon-rs

% find ~/sqlite-parser/test/sql/official-suite/ -type f | xargs ./target/debug/examples/sql_cmds 2> errors.txt > /dev/null
MarinPostma commented 5 months ago

oh that's cool! thanks @gwenn I'll give it a shot 👍

gwenn commented 5 months ago

See https://github.com/sqlite/sqlite/blob/d31fc6e9cfd4d25d2fdea2f5aa41fee0a1d5e80c/test/window1.test#L1924

SELECT (SELECT max(x)OVER(ORDER BY x) % min(x)OVER(ORDER BY CASE x WHEN 889 THEN x WHEN x THEN x END)) FROM (SELECT (SELECT sum(CAST(a IN(SELECT (SELECT max(x)OVER(ORDER BY CASE x WHEN 889 THEN 299 WHEN 863 THEN 863 END)) FROM (SELECT (SELECT sum(CAST((SELECT (SELECT max(x)OVER(ORDER BY x) / min(x)OVER(ORDER BY CASE x WHEN 889 THEN 299 WHEN -true THEN 863 END)) FROM (SELECT (SELECT sum(CAST(a IN(SELECT (SELECT max(x) & sum ( a )OVER(ORDER BY CASE x WHEN -8 THEN 299 WHEN 863 THEN 863 END)) FROM (SELECT (SELECT sum(CAST(a AS )) FROM t1) AS x FROM t1)) AS t1 )) FROM t1) AS x FROM t1)) AS x )) FROM t1) AS x FROM t1)) AS real)) FROM t1) AS x FROM t1)
;

which reduces to

SELECT sum(CAST(a AS )) FROM t1

=> https://github.com/gwenn/lemon-rs/blob/3910b4654d6b86bdd77390cedba8bc56d1090be4/src/parser/parse.y#L915