Repository navigation
Conversation
When given a poorly formed regular expression depending on data the regular expression matching can take a long time to compute. This commit modifies the expression engine so that regular expression based functions time bound evaluation to avoid runaway expressions.
Ensures that the ARQ property function strSplit time bounds regular expression splitting time
REPLACE uses regular expressions to perform replacements so also impose regular expression limits on its evaluation
Shex regular expression constraints could run too long depending on the regular expression and data combinations. This commit uses the shared RegexEngine.timeBounded() mechanism to limit evaluation time. Also disables a test scenario where optimisation effects means that the test does not reliably fail so is not a useful stable test.
afs
reviewed
Oct 10, 2026
|
|
||
| @ParameterizedTest(name = "{1}") | ||
| @MethodSource("slowSplits") | ||
| public void givenSlowRegex_whenSplittingWithTimeLimit_thenFails(String data, String pattern, int expectedResultCount) { |
Member
There was a problem hiding this comment.
A more human oriented name perhaps.
|
|
||
| @ParameterizedTest(name = "{1}") | ||
| @MethodSource("slowSplits") | ||
| public void givenSlowRegex_whenSplittingWithNoTimeLimit_thenEventuallySucceeds(String data, String pattern, int expectedResultCount) { |
Member
There was a problem hiding this comment.
A more human oriented name perhaps.
|
|
||
| @ParameterizedTest(name = "{1}") | ||
| @MethodSource("backtrackingRegex") | ||
| public void givenBacktrackingRegex_whenEvaluatingRegexWithoutTimeLimit_thenEventuallyCompletes(String input, String pattern, String flags, boolean shouldMatch) { |
Member
There was a problem hiding this comment.
A more human oriented name perhaps.
|
|
||
| @ParameterizedTest(name = "{1}") | ||
| @MethodSource("backtrackingRegex") | ||
| public void givenBacktrackingRegex_whenEvaluatingRegexWithTimeLimit_thenFails(String input, String pattern, String flags, boolean shouldMatch) { |
Member
There was a problem hiding this comment.
A more human oriented name perhaps.
afs
reviewed
Oct 10, 2026
| * Default maximum permitted regular expression evaluation time | ||
| * @see #MAX_REGEX_EVALUATION_TIME | ||
| */ | ||
| public static final long DEFAULT_MAX_REGEX_EVALUATION_TIME = 250; |
Member
There was a problem hiding this comment.
I think it would be useful to put all limits (settings and defaults) in one place, including MathLimits from #4276. It makes things findable.
One possible place is org.apache.jena.sparql.ARQConstants; another is a new class for this purpose org.apache.jena.sparql.SysLimits.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Various SPARQL functions and Jena provided extension functions provide access to regular expressions. Depending on the expression and data combination some regular expressions can take too long to run leading to slow queries. This PR bounds regular expression evaluation time via statically controlled limits so regular expressions that take too long to run are aborted with an
ExprEvalException.As ShEx also uses the same Jena subsystem is was also upgraded to apply limits.
By submitting this pull request, I acknowledge that I am making a contribution to the Apache Software Foundation under the terms and conditions of the Contributor's Agreement.
See the Apache Jena "Contributing" guide.