Bug #77642

preg_match: Compilation failed: regular expression is too large at offset 27

Added by Tobias Schaefer almost 5 years ago. Updated about 1 year ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Frontend
Target version:
-
Start date:
2016-08-25
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
11
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

If the cropHTML function (typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php) is called to crop at 1074 (or more) characters it fails with this error message:
PHP Warning: preg_match(): Compilation failed: regular expression is too large at offset 27 in typo3/sysext/frontend/Classes/ContentObject/ContentObjectRenderer.php

Increasing pcre.backtrack_limit or pcre.recursion_limit in php.ini doesn't help.
To reproduce the bug you can use the news extension. Create a news with a teaser text of more the 1073 characters and set up the list plugin to crop the teaser text at 1074 characters. Cropping at 1073 characters will work.

Here you find a discussion about this problem:
http://stackoverflow.com/questions/31172837/regular-expression-is-too-large-error-in-php

Possible solutions:
- If you are trying to match/parse HTML, I would recommend using DOMDocument to parse the HTML and then walk the DOM tree or build an XPATH to find what you're looking for.
- Shorten the Regular Expression by using DEFINE for any redundant sub-expressions (see below).
- Split your regular expression at | and process the resulting sub-expressions separately. If the regex is essentially numerous keywords separated by |, then converting to a strtok or a loop with strpos may be a better & faster choice.

TYPO3: 6.2.26
PHP: 5.5.14
Linux: SLES 12 SP1

Cheers,
Tobias

Also available in: Atom PDF