kaleidawave / ezno

A JavaScript compiler and TypeScript checker written in Rust with a focus on static analysis and runtime performance
https://kaleidawave.github.io/posts/introducing-ezno/
MIT License
2.3k stars 42 forks source link

Panic when parsing let declaration with no declarations #154

Closed jasikpark closed 1 week ago

jasikpark commented 1 month ago
!!sqve+l//

l
let
///
oOo�str!er

as input for the module_roundtrip_naive fuzzer produces this error:

Running: fuzz/artifacts/module_roundtrip_naive/crash-cbb815ba074710aad65fc66c094f2e1600e0c80e
thread 'AST parsing' panicked at /Users/calebjasik-personal/Git/ezno/parser/src/declarations/variable.rs:274:63:
called `Option::unwrap()` on a `None` value

https://github.com/kaleidawave/ezno/blob/34eecf1198229424560bf390fd87b0ec82d407db/parser/src/declarations/variable.rs#L273-L276

jasikpark commented 1 month ago

Seems like there needs to be an error thrown when there's a let but no associated declaration?

kaleidawave commented 1 month ago

Hmm yes. Could start with let mut declarations = vec![VariableDeclarationItem::from_reader(...)] but yes emitting a ParseError if declarations.is_empty would be better because it could be allowed under partial_syntax so that this works

Will investigate and fix! (also same issue for const below and will check for var)

jasikpark commented 1 month ago

I'm thinking I may do work to integrate these mature fuzzers with OSS-Fuzz, where they can be run for longer and catch bugs like these, since it seems like they aren't catching anything on 5m Github Action runs anymore, right?

(https://google.github.io/oss-fuzz/getting-started/continuous-integration/)

kaleidawave commented 1 month ago

There are things being caught! I am unsure how this example hadn't been flagged by CI yet? Maybe just a rare state.

ATM things in the type checker have a lot higher priority so I am quite happy with the current level of parsing fuzzing. If you want to and is simple to change/upgrade sure! I do want to keep it under 2 mins though, it is a bit annoying to wait any longer for results.

kaleidawave commented 1 week ago

Fixed in https://github.com/kaleidawave/ezno/pull/158