Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Use `new SecureRandom()` to avoid blocking ([18729](https://github.com/opensearch-project/OpenSearch/issues/18729))
- Use ScoreDoc instead of FieldDoc when creating TopScoreDocCollectorManager to avoid unnecessary conversion ([#18802](https://github.com/opensearch-project/OpenSearch/pull/18802))
- Fix leafSorter optimization for ReadOnlyEngine and NRTReplicationEngine ([#18639](https://github.com/opensearch-project/OpenSearch/pull/18639))
- Fix query string regex queries incorrectly swallowing TooComplexToDeterminizeException ([#18883](https://github.com/opensearch-project/OpenSearch/pull/18883))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.automaton.RegExp;
import org.apache.lucene.util.automaton.TooComplexToDeterminizeException;
import org.opensearch.common.lucene.search.Queries;
import org.opensearch.common.regex.Regex;
import org.opensearch.common.unit.Fuzziness;
Expand Down Expand Up @@ -795,7 +796,9 @@ private Query getRegexpQuerySingle(String field, String termStr) throws ParseExc
termStr = getAnalyzer().normalize(currentFieldType.name(), termStr).utf8ToString();
return currentFieldType.regexpQuery(termStr, RegExp.ALL, 0, getDeterminizeWorkLimit(), getMultiTermRewriteMethod(), context);
} catch (RuntimeException e) {
if (lenient) {
// Lenient queries are intended for data type mismatches, but TooComplexToDeterminizeException
// comes up from the same place in the code. Don't create a lenient query in this case.
if (lenient && !(e instanceof TooComplexToDeterminizeException)) {
return newLenientFieldQuery(field, e);
}
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,14 @@ public void testToQueryRegExpQueryTooComplex() throws Exception {
TooComplexToDeterminizeException.class,
() -> queryBuilder.toQuery(createShardContext())
);
assertThat(e.getMessage(), containsString("Determinizing automaton"));
assertThat(e.getMessage(), containsString("would require more than 10000 effort"));
assertTrue(e.getMessage().contains("Determinizing automaton"));
assertTrue(e.getMessage().contains("would require more than 10000 effort"));

// TooComplexToDeterminizeException should be thrown even if lenient is true
QueryStringQueryBuilder lenientQueryBuilder = queryStringQuery("/[ac]*a[ac]{50,200}/").defaultField(TEXT_FIELD_NAME).lenient(true);
e = expectThrows(TooComplexToDeterminizeException.class, () -> lenientQueryBuilder.toQuery(createShardContext()));
assertTrue(e.getMessage().contains("Determinizing automaton"));
assertTrue(e.getMessage().contains("would require more than 10000 effort"));
}

/**
Expand Down
Loading