Skip to content

[ErrorHandler] "Backtrack limit exhausted" in the HtmlErrorRenderer #51290

Closed
@aragon999

Description

@aragon999

Symfony version(s) affected

6.3.2

Description

Currently when one is in debug mode and has a large error message, it might that the following error occurs:

[TypeError]
HTTP 500 Internal Server Error
Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer::formatFileFromText(): Return value must be of type string, null returned

Which is not due to the original error, but rather a problem in the error rendering.

The problematic place seems to be: https://github.com/symfony/error-handler/blob/6.3/ErrorRenderer/HtmlErrorRenderer.php#L307 which returns null in that case. When I dug deeper into the code, I found that this preg_replace_callback method errors out (preg_last_error_msg()) with the error: Backtrack limit exhausted and hence the type error is thrown.

How to reproduce

Not sure how to general reproduce the error, in my case it was a twig error, with a large context.

To reproduce this particular error, use Shopware, and create an invalid twig template, e.g. add for example a {{ at the end of this line (without closing): https://github.com/shopware/platform/blob/trunk/src/Storefront/Resources/views/storefront/base.html.twig#L15

In my case this produces an error text, with 6_547_276 characters.

Possible Solution

I tried to solve this error, by cutting the text or returning early, if the $text exceeds a particular length. But with these changes I do not give any response (the error message still shows up in the log though).

As far as I can tell, the regex does not match anything within the twig error text, as it is mostly the context of the twig templates, so I am not sure how to properly proceed, or where this should be fixed.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions