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 of all, thank you very much for maintaining this project!
I'm hoping that someone can provide a bit of guidance. I apologize in advance for not having a minimal test case to reproduce this issue.
The issue
I've been doing some fuzz testing on OPA and I ran into one case where certain inputs would cause the program to hang and then crash. Here's a snippet of the crash:
I modified the code to print the size of the maxFailExpected slice and found that it grew to very large sizes in pathological cases. For example the input {{{{{{{{ takes 3.5s to parse (error) and the slice holds around 3,000,000 elements.
Expected behaviour
It's not clear whether much can be done about this. In the case of OPA, we don't display the expected values (because we found them too noisy to be helpful) so disabling the code that generates them is an option, however, I'm not sure that would resolve the problem because valid inputs with a similar structure also take a very long time to parse (e.g., {{{{{{{{}}}}}}}} takes ~1.5s before succeeding.)
The line in parser.go you are pointing to (https://github.com/open-policy-agent/opa/blob/master/ast/parser.go#L4362) is after the parsing of the input has finished and is building a map of all the possible expected values in the farthest parsing position until which the parser could advance. The purpose of this map is to easily remove duplicates from the list of possible expected values. It makes sense to me, that with the slice containing 3 mio elements, that could become a problem. Especially, because the map to hold the expected values is initialized on the size of the slice (which does not make sense with slices that big, because chances are really big, that there are a lot duplicates. With so many expected values I also understand, that you disabled those, because they are to noisy.
I think part of the problem is by design (back tracking nature of PEG parsers). PEG parsers are know to behave badly in pathological edge cases.
In regards to possible solutions, I can think of adding some checks to prevent such large slices and maps, especially for the expected values. Also completely disable this functionality as an option could be done. Maybe I can come up with other solutions, if I think a little bit more intensely about this.
Hello!
First of all, thank you very much for maintaining this project!
I'm hoping that someone can provide a bit of guidance. I apologize in advance for not having a minimal test case to reproduce this issue.
The issue
I've been doing some fuzz testing on OPA and I ran into one case where certain inputs would cause the program to hang and then crash. Here's a snippet of the crash:
The crash above occurs here: https://github.com/open-policy-agent/opa/blob/master/ast/parser.go#L4362
I modified the code to print the size of the
maxFailExpected
slice and found that it grew to very large sizes in pathological cases. For example the input{{{{{{{{
takes 3.5s to parse (error) and the slice holds around 3,000,000 elements.Expected behaviour
It's not clear whether much can be done about this. In the case of OPA, we don't display the expected values (because we found them too noisy to be helpful) so disabling the code that generates them is an option, however, I'm not sure that would resolve the problem because valid inputs with a similar structure also take a very long time to parse (e.g.,
{{{{{{{{}}}}}}}}
takes ~1.5s before succeeding.)The PEG file is here: https://github.com/open-policy-agent/opa/blob/master/ast/rego.peg
The vendored version is bb0192c.
Any suggestions would be appreciated.
The text was updated successfully, but these errors were encountered: