-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
shorthand syntax parser fails silently and delivers raw template #556
Comments
Very nicely spotted, @moenadic! This seems like a valid solution and I've not been able to determine any negative effects from it; the original intention of the The unit tests should indeed be extended here, to include examples of inline expressions with multiple spaces and linebreaks/indentations, plus some examples of arbitrary multiple whitespace within expressions. We might also add a unit test that confirms that things like inline style brackets at least won't be detected as Fluid - but we can't do the same for embedded JSON or JS function curlies since the only reason CSS isn't mis-detected is the |
Great find and solid proposed fix. I remember running into the same error with the same regex in 2016 when upgrading to PHP 7.0, but I don't remember the exact circumstances. Most likely they were similiar to those experienced by @moenadic . I think we found a workaround at the time, but this was most likely the root cause. Please fix like proposed, as already mentioned the behaviour of the regex shouldn't change at all from removing the duplicate quantity modifier. |
Would it be possible to fix this in a release soon? Is any more input required? I would hate to have to have a private fork for this single issue. It is currently blocking our PHP version upgrade, though. |
@moenadic You can apply a Composer patch in the meantime. |
When upgrading a legacy PHP app from 7.2 to 7.4, I encountered an error where the regex engine errored out with
preg_last_error() = 2
,preg_last_error_msg() = "Backtrack limit exhausted"
.I propose the following actions:
preg_last_error()!==0
. Gettingfalse
for "expression did not match" should be treated differently from "we ran into catastrophic backtracking and gave up". In the latter case returning the raw string might do anything, from breaking the site to exposing secrets; and in complete silence, not even a log entry to be found.Fluid/src/Core/Parser/TemplateParser.php
Line 662 in 3420f8c
Patterns::$SPLIT_PATTERN_SHORTHANDSYNTAX
and remove the+
quantifier from the|\s
alternate pattern. Repetition of the outer non-capturing group also matches all the spaces but by disambiguating quantifiers will prevent catastrophic backtracking (at least in all cases I could throw against it).See in action here on regex101 to debug and test. This sample includes all the test cases I found in the unit tests and correctly recognizes them. The last part with the style tag is a crafted example that reliably provokes catastrophic backtracking for the original regex.
Disclaimer: The above fix should work correctly. So far I have not found any adverse effects on test systems. But since the unit tests only cover part of the problem space, a definitive verdict cannot be given.
The text was updated successfully, but these errors were encountered: