[ https://issues.apache.org/jira/browse/LUCENE-10651?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17568068#comment-17568068 ]
Michael McCandless commented on LUCENE-10651: --------------------------------------------- It's a bit depressing that {{SimpleQueryParser}} consumes Java's stack in proportion to the number of clauses. Though, it is "simple", and just recursing to parse another clause is indeed simple. Too bad we seem to have lost tail recursion from the Lisp days ... This is really a bug/imitation in {{{}SimpleQueryParser{}}}. E.g. a user may increase that clause limit and then try to parse a {{BooleanQuery}} that should work (doesn't have too many clauses) yet hits {{{}StackOverflowException{}}}. I wonder if our other query parsers have this problem too? But I like your fix – it prevents a {{StackOverflowException}} when the returned Query would have failed with {{TooManyClauses}} anyways. It's at least progress not perfection? > SimpleQueryParser stack overflow for large nested queries. > ---------------------------------------------------------- > > Key: LUCENE-10651 > URL: https://issues.apache.org/jira/browse/LUCENE-10651 > Project: Lucene - Core > Issue Type: Bug > Affects Versions: 9.1, 8.10, 9.2, 9.3 > Reporter: Marc Handalian > Priority: Major > > The OpenSearch project received an issue [1] where stack overflow can occur > for large nested boolean queries during rewrite. In trying to reproduce this > error I've also encountered SO during parsing where queries expand beyond the > default 1024 clause limit. This unit test will fail with SO: > {code:java} > public void testSimpleQueryParserWithTooManyClauses() { > StringBuilder queryString = new StringBuilder("foo"); > for (int i = 0; i < 1024; i++) { > queryString.append(" | bar").append(i).append(" + baz"); > } > expectThrows(IndexSearcher.TooManyClauses.class, () -> > parse(queryString.toString())); > } > {code} > I would expect this case to also fail with TooManyClauses, is my > understanding correct? If so, I've attempted a fix [2] that during parsing > increments a counter whenever a clause is added. > [1] [https://github.com/opensearch-project/OpenSearch/issues/3760] > [2] > [https://github.com/mch2/lucene/commit/6a558f17f448b92ae4cf8c43e0b759ff7425acdf] > -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org