[ 
https://issues.apache.org/jira/browse/CAMEL-27576?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Federico Mariani resolved CAMEL-27576.
--------------------------------------
    Resolution: Fixed

> camel-ai-resource: uriTemplate matcher fails on long path-segment values
> ------------------------------------------------------------------------
>
>                 Key: CAMEL-27576
>                 URL: https://issues.apache.org/jira/browse/CAMEL-27576
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-ai
>            Reporter: Federico Mariani
>            Assignee: Federico Mariani
>            Priority: Minor
>             Fix For: 4.24.0
>
>
> {{AiResourceUriTemplate}} (added by CAMEL-26354) matches each template 
> variable with this pattern:
> {noformat}
> (?:[A-Za-z0-9._~!$&'()*+,;=:@-]|%[0-9A-Fa-f]{2})+
> {noformat}
> The group contains an alternation and is repeated by a greedy quantifier. 
> {{java.util.regex}} handles such a repetition recursively, using one stack 
> frame per repetition. A variable value of a few thousand characters therefore 
> throws {{StackOverflowError}} from {{match()}} instead of matching. For 
> example, {{crm://customers/\{id\}}} fails for an {{id}} of about 5,000 
> characters on a default thread stack.
> {{match()}} runs when an MCP server reads a resource through a template, 
> before the route is called. A read with such a URI fails with a server error 
> instead of reaching the route, and the error is logged with a long stack 
> trace.
> A variable always occupies a whole path segment. It is followed by {{/}} or 
> by the end of the URI, and {{%}} is not part of the single-character class. 
> The matcher therefore never needs to backtrack into a variable.
> Proposed change:
> * Make the quantifier possessive ({{)++}}). The engine then repeats the group 
> iteratively, and the matching result is unchanged for every input.
> * Add tests:
> ** long values (100,000 characters, and 50,000 percent-encoded octets) match 
> and are returned verbatim;
> ** a long value followed by a character outside the segment grammar is 
> refused.
> Only main is affected. The URI template support is not in a released version.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to