fix(search): reject parentheses nested deeper than 64 levels
Deep nesting overflowed the stack of the recursive Pidgin parser (around 400-700 levels), an uncatchable crash. The depth is now checked on the token stream before parsing and reported as a syntax error. Listed in PLAN 6.2 and USAGE.
This commit is contained in:
1 parent
8ae9780c0e
commit
d2a5d36bd2
5 files changed
+70
-2
No files matched your search
@@ -227,6 +227,33 @@ public class SearchQueryParserTests
|
||||
AssertSyntaxError("a)");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NestingAtTheDepthLimitParses()
|
||||
{
|
||||
int depth = SearchQueryParser.MaxNestingDepth;
|
||||
AssertParsesTo(new SearchNode.FreeText("a"), new string('(', depth) + "a" + new string(')', depth));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void NestingBeyondTheDepthLimitIsAnError()
|
||||
{
|
||||
int depth = SearchQueryParser.MaxNestingDepth + 1;
|
||||
AssertSyntaxError(new string('(', depth) + "a" + new string(')', depth));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SequentialGroupsDoNotCountTowardsTheDepthLimit()
|
||||
{
|
||||
string groups = string.Join(" ", Enumerable.Repeat("(a)", SearchQueryParser.MaxNestingDepth + 1));
|
||||
Assert.IsNotNull(SearchQueryParser.Parse(groups));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VeryDeepNestingIsAnErrorRatherThanACrash()
|
||||
{
|
||||
AssertSyntaxError(new string('(', 100_000) + "a" + new string(')', 100_000));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void EmptyParensAreAnError()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user