Special instruction ends in infinite loop consuming 100% CPU
The following instruction kills the fluid parse
{'{1 == 1 ? 1 : 2}'}
Looks like the parser runs in an infinite loop.
I'll check the recursion issue but I should note that the expression is definitely not going to be supported. I assume these are placeholder values, but:
- Ternary conditions do not support expressions as such, they only support an input variable that has to be truthy to make the true side evaluate.
- The resulting expression even if it worked would recursively resolve to first
{'1'}which does not get recognised as a variable both because of the quotes and the numeric character that would come first even if the quoted content was evaluated as variable name.
The cause could very well be not this expression itself but the way it exists within the larger template and in particular what comes after it. Because invalid characters are used (1 == 1 for example is treated as if it were a variable reference and = is not valid as character in variables and won't be detected) what you're experiencing could in reality be that a much larger chunk of template code is recursing because the expression causes node detection to go completely wrong after that piece of code.
Just in case you beat me to it in terms of reproducing this: does this still happen with a valid ternary expression, without the single-quotes and using a variable name not beginning with a number?
I would not expect that something like this does work. Just stumbled over the hanging process while refactoring a template.
You can simply add this example to the expression example html file and then run the example. It'll hang.
I have another expression that kills the Fluid Parser:
<f:if condition="{var}=='test"> <f:then> Error </f:then> <f:else> No Error </f:else> </f:if>
Mind the missing ' after test. I would have expected for this expression to throw me an error but instead the Fluid Parser never finishes.
Same:
<f:if condition="{pageLayout} == 'page-layout-3">
<f:image src="{splashImage}" treatIdAsReference="1" />
</f:if>
The missing ' after page-layout-3 breaks the show - 100% CPU and no end to it.
(Fluid 2.6, TYPO3 10.4; Cannot update to Fluid 3.0 because https://github.com/TYPO3GmbH/blog/issues/146)
@LeoniePhiline you can composer req typo3/fluid:"^3 as 2.6.9" to give the blog package the Fluid version it expects. It would be really useful if you could check whether the issue still occurs on Fluid 3.
Without testing, I expect Fluid 3.0 to either report a parsing error or parse much more content than expected, as part of the single-quoted string.
Main problem here is that 2.x uses regular expressions and the infinite loop happens internally in the PCRE engine - which means there's not much we can do about this special case. Other than, of course, asking you to fix the template syntax error.
there's not much we can do about this special case
RegEx should be designed for failure. This seems to be a classic back-tracking explosion inside PCRE. I honestly have not looked into the RegEx yet, but just by reading this seems to be the case.
https://github.com/TYPO3/Fluid/commit/7d0b08409ac5b9567819442e71ec2059a99003fd fixed https://github.com/TYPO3/Fluid/issues/439#issuecomment-549701781 and https://github.com/TYPO3/Fluid/issues/439#issuecomment-617987441
https://github.com/TYPO3/Fluid/commit/7d0b08409ac5b9567819442e71ec2059a99003fd also fixes the initial case and throws an exception now - no infinite loop