apache / apache/lucene

SimpleQueryParser stack overflow for large nested queries. [LUCENE-10651]

Open
#11,687 3 comments 0 reactions 0 assignees View on GitHub
affects-version:8.10 affects-version:9.1 affects-version:9.2 affects-version:9.3 legacy-jira-priority:Major type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

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:

```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()));
}

```

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]

 [2]

---
Migrated from [LUCENE-10651](https://issues.apache.org/jira/browse/LUCENE-10651) by Marc Handalian (@mch2), 1 vote, updated Jul 18 2022

Contributor guide

Open the contributing guide

Research direction

Start with SimpleQueryParser and the testSimpleQueryParserWithTooManyClauses test described in the issue; run it to reproduce the stack overflow while parsing a query beyond the clause limit. Trace the parse path around parse(queryString) and IndexSearcher.TooManyClauses, and consider the work complete when the test reports TooManyClauses rather than a stack overflow.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
search
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.