Skip to content

Recursive Parser has no limit, leading to stack overflow on deeply nested inputs #399

Description

@Sahilgill24

Project version

0.7.2

Project

compiler

What happened?

The chumsky recursive parser (src/parse.rs:2599) re-enters itself once every nesting level of either a block or paranthesis without any depth counter, so for each level a stack frame is pushed and after a certain level of nesting the stack threshold is reached and the Process gets aborted.

Moreover the type parser in (src/parse.rs:1929) also does not have a depth counter, so ideally it could be recreated with nested types as well. I have added an example with paranthesis in the reproduction steps.

This could also lead to a trivial DoS attack on any service that compiles .simf files.

Minimal reproduction steps

fn main() {
    let x: u32 = ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
        (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
        (((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
        ((((((((((((((((((0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
        )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
        )))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
        ))))))))))))))))))))));
    assert!(jet::eq_32(x, 0));
}

I tried this upto 300 paranthesis and it starts getting overflow around 150 ish and compiles correctly till 100

error

thread 'main' (5532049) has overflowed its stack
fatal runtime error: stack overflow, aborting
[1]    49397 abort      ./target/debug/simc ./bug.simf

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions