Bug #4527
closedRegex with grouping and escape triggers java.lang.IndexOutOfBoundsException
100%
Description
When working with saxon-he 10, we noticed that in some cases a regex used either in xsl:analyze-string or fn:matches causes saxon to exit with a stack-trace.
The circumstances are pretty hard to trigger.
- the sequence/node/value that is matched against the regex needs to evaluate to an empty string.
- the regex
- two levels of grouping
- the first level of grouping needs to cover the whole regex
- the second level needs to be an alternative of patterns
- the second level needs to be at the immediate beginning of the pattern
- after the second grouping a pattern with two or more characters need to follow, one of which needs to be optional
- the regex is not anchored at the start of the string with '^'
<xsl:stylesheet version="3.1"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>
<xsl:template match="/">
<xsl:value-of select="matches('','((a|b)cd?)')"/>
</xsl:template>
</xsl:stylesheet>
I know boiled down to this minimal example this looks hilarious. And sure, the outer grouping is not needed and with this, the error goes away. But still the regex as such should be valid and working. A colleague of mine ran into this while developing a rather complex transformation. As the regex appears to correct, and saxon has friendlier ways of indicating syntactically wrong regexes, I think this time it is a bug, usually it is just us as saxon is regarded the reference at our shop.
when run with saxon 10 he:
echo '<ok/>' | java -classpath /home/sm/git/saxon/share/java/saxon-he-10.0.jar net.sf.saxon.Transform -s:- analyze_function_bug.xsl
java.lang.IndexOutOfBoundsException
at net.sf.saxon.regex.EmptyString.uCharAt(EmptyString.java:30)
at net.sf.saxon.regex.Operation$OpAtom.iterateMatches(Operation.java:637)
at net.sf.saxon.regex.REMatcher.checkPreconditions(REMatcher.java:494)
at net.sf.saxon.regex.REMatcher.match(REMatcher.java:426)
at net.sf.saxon.regex.ARegularExpression.containsMatch(ARegularExpression.java:90)
at net.sf.saxon.functions.Matches.call(Matches.java:78)
at net.sf.saxon.functions.Matches.call(Matches.java:24)
at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:543)
at net.sf.saxon.expr.AtomicSequenceConverter.iterate(AtomicSequenceConverter.java:297)
at net.sf.saxon.expr.Expression.process(Expression.java:948)
at net.sf.saxon.expr.instruct.ValueOf.processLeavingTail(ValueOf.java:332)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:374)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:555)
at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:669)
at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:360)
at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:285)
at net.sf.saxon.Transform.processFile(Transform.java:1300)
at net.sf.saxon.Transform.doTransform(Transform.java:840)
at net.sf.saxon.Transform.main(Transform.java:82)
java.lang.RuntimeException: Internal error evaluating template rule at line 4 in module file:/home/sm/git/bruckneruni/xslt/bug_function_analyze/analyze_function_bug.xsl
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393)
at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:555)
at net.sf.saxon.trans.XsltController.applyTemplates(XsltController.java:669)
at net.sf.saxon.s9api.AbstractXsltTransformer.applyTemplatesToSource(AbstractXsltTransformer.java:360)
at net.sf.saxon.s9api.Xslt30Transformer.applyTemplates(Xslt30Transformer.java:285)
at net.sf.saxon.Transform.processFile(Transform.java:1300)
at net.sf.saxon.Transform.doTransform(Transform.java:840)
at net.sf.saxon.Transform.main(Transform.java:82)
Caused by: java.lang.IndexOutOfBoundsException
at net.sf.saxon.regex.EmptyString.uCharAt(EmptyString.java:30)
at net.sf.saxon.regex.Operation$OpAtom.iterateMatches(Operation.java:637)
at net.sf.saxon.regex.REMatcher.checkPreconditions(REMatcher.java:494)
at net.sf.saxon.regex.REMatcher.match(REMatcher.java:426)
at net.sf.saxon.regex.ARegularExpression.containsMatch(ARegularExpression.java:90)
at net.sf.saxon.functions.Matches.call(Matches.java:78)
at net.sf.saxon.functions.Matches.call(Matches.java:24)
at net.sf.saxon.expr.FunctionCall.iterate(FunctionCall.java:543)
at net.sf.saxon.expr.AtomicSequenceConverter.iterate(AtomicSequenceConverter.java:297)
at net.sf.saxon.expr.Expression.process(Expression.java:948)
at net.sf.saxon.expr.instruct.ValueOf.processLeavingTail(ValueOf.java:332)
at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:374)
... 7 more
Fatal error during transformation: java.lang.RuntimeException: Internal error evaluating template rule at line 4 in module file:/home/sm/git/bruckneruni/xslt/bug_function_analyze/analyze_function_bug.xsl
Please register to edit this issue