You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, thank you so much for peg. I am an happy user since 2018.
I have one feature request, would it be possible to limit the recursion depth of parsers and return a nice error instead of having the currently parsing thread crashing on too nested inputs with a stack overflow error?
For example if I write the grammar:
pub rule arithmetic() -> i64 = precedence!{
x:(@) "+" y:@ { x + y }
x:(@) "-" y:@ { x - y }
--
n:number() { n }
"(" e:arithmetic() ")" { e }
}
and give for input ((((((((((((((((1)))))))))))))))) the parser generated by peg will recuse 16 times to parse the content. An ill intentioned user can give for input to the parser a nested enough input to trigger a stack overflow.
A possible nice way to circumvent this problem in a generic manner might be to give to the parser generator a maximal allowed stack size and, if this parameter is provided, increment/decrement a counter at all rules entry/exit and return an error if the content reaches the threshold. But there is maybe a nicer solution I don't see.
What do you think about it?
The text was updated successfully, but these errors were encountered:
How the error is exposed in the API when limit is exceeded
I don't think there's a good way to expose this error at the moment. Maybe it's worth introducing a new kind of error that shuts parsing down entirely (without considering further alternatives)? In any case, I think that should be considered as a separate issue.
So for now we're left with two poor choices:
panic immediately
treat the limit breach as a rule failure (without attempting to match the rule), and add a special string to the list of expected symbols to help the end-user diagnose
zsol
linked a pull request
Jun 29, 2022
that will
close
this issue
First, thank you so much for
peg
. I am an happy user since 2018.I have one feature request, would it be possible to limit the recursion depth of parsers and return a nice error instead of having the currently parsing thread crashing on too nested inputs with a stack overflow error?
For example if I write the grammar:
and give for input
((((((((((((((((1))))))))))))))))
the parser generated bypeg
will recuse 16 times to parse the content. An ill intentioned user can give for input to the parser a nested enough input to trigger a stack overflow.A possible nice way to circumvent this problem in a generic manner might be to give to the parser generator a maximal allowed stack size and, if this parameter is provided, increment/decrement a counter at all rules entry/exit and return an error if the content reaches the threshold. But there is maybe a nicer solution I don't see.
What do you think about it?
The text was updated successfully, but these errors were encountered: