Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

Compilation failed: internal error: previously-checked referenced subpattern not found #259

Closed
ontonto opened this issue Nov 3, 2012 · 32 comments

Comments

@ontonto
Copy link

ontonto commented Nov 3, 2012

While using swiftmailer with apache 2, php 5.4.7 (XAMPP 1.8.1) I get the following warning and fails to deliver the message:

preg_match(): Compilation failed: internal error: previously-checked referenced subpattern not found at offset 4246

at swiftmailer/library/classes/Swift/Mime/Headers/MailboxHeader.php on line 306

The regexp in question is the following:

/^(?:(?:(?:(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?(?:[a-zA-Z0-9!#\$%&'\*\+\-\/=\?\^_`\{\}\|~]+(\.[a-zA-Z0-9!#\$%&'\*\+\-\/=\?\^_`\{\}\|~]+)*)+(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])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E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?))))$/D

The problem only occurs when the page is served through apache. When I run a copy the regexp to a test file and validate against that, it does not issue the warning.

I have temporarily "solved" the problem by removing the validation altogether. However, I hope there is a better solution.

Thank you!

@ontonto
Copy link
Author

ontonto commented Dec 2, 2012

Similarly:

preg_match(): Compilation failed: internal error: previously-checked referenced subpattern not found at offset 2077

at swiftmailer/library/classes/Swift/Mime/Headers/AbstractHeader.php on line 252

The regexp here is:

(?:(?:(?:(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?[a-zA-Z0-9!#\$%&'\*\+\-\/=\?\^_`\{\}\|~]+(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t])|(?:(?:[\x01-\x08\x0B\x0C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))*(?:(?:(?:(?:[ \t]*(?:\r\n))?[ \t])?(\((?:(?:(?:[ \t]*(?:\r\n))?[ \t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C\x0E-\x19\x7F]|[\x21-\x27\x2A-\x5B\x5D-\x7E])|(?:\\[\x00-\x08\x0B\x0C\x0E-\x7F])|(?1)))*(?:(?:[ \t]*(?:\r\n))?[ \t])?\)))|(?:(?:[ \t]*(?:\r\n))?[ \t])))?))+?)

@swquinn
Copy link

swquinn commented Apr 13, 2013

I'm running into the same issue; on Windows, using XAMPP with PHP 5.4.7 the regex compiles without an issue but running the same code with the same email addresses in an Ubuntu 12.10 Linux environment results in this error at the same subpattern position.

Like you, I also pulled the regex out and tested it in isolation: it works.

Have you found any indication why this would fail when served through Apache?

@ontonto
Copy link
Author

ontonto commented Apr 16, 2013

No. However I did find a similar issue occuring in Drupal (http://drupal.org/node/1286046) which stated that upgrading the PCRE library does solve the issue. I have not tried it but that might be the issue.

@Lucas-Malor
Copy link

@Developers: why don't you use the PHP built-in function? I solved this bug using

if (! filter_var($address, FILTER_VALIDATE_EMAIL))

instead of

if (!preg_match('/^' . $this->getGrammar()->getDefinition('addr-spec') . '$/D', $address))

on line 349 of Swift/Mime/Headers/MailboxHeader.php

@xdecock
Copy link
Member

xdecock commented Jun 7, 2013

because the built-in function does not work correctly and does not validate
every mail, does validate invalid emails, and change from version to
version.

On Fri, Jun 7, 2013 at 10:18 AM, Lucas-Malor notifications@github.comwrote:

@Developers https://github.com/developers: why don't you use the PHP
built-in function? I solved this bug using

if (! filter_var($address, FILTER_VALIDATE_EMAIL))

instead of

if (!preg_match('/^' . $this->getGrammar()->getDefinition('addr-spec') . '$/D', $address))

on line 349 of Swift/Mime/Headers/MailboxHeader.php


Reply to this email directly or view it on GitHubhttps://github.com//issues/259#issuecomment-19094567
.

Xavier De Cock
GPG Fingerprint: 93CA EE3F 9F57 5BE1 AE4A 794D 3C74 CA9E E7A5 0C1B
GPG Id: 0xE7A50C1B

@Lucas-Malor
Copy link

See also PHPMailer solution, row 773:

https://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.php

Anyway FILTER_VALIDATE_EMAIL works well with php >= 5.3.9

@shachibista
Copy link

Any news on this?

@mzur
Copy link

mzur commented Mar 4, 2015

Is there now any news on this? I'm currently experiencing this error with my Laravel application and am desperately searching for the cause. It seems to appear only with certain configurations involving an Apache. My setup runs recent versions of PHP, Apache and PRCE but the error still persists.

Edit: The problem was a mismatch of PCRE versions of the system and Apache. A libphp5.so rebuilt against the system libpcre solved it.

@smelchior
Copy link

Is there any update on this? We are currently experiencing this issue with the current 5.6.9 dotdeb packages. In 5.6.9 the PCRE Version was updated to 8.37 (http://php.net/ChangeLog-5.php#5.6.9) and this does not seem to play well with the swiftmailer regex.

@cpocholle
Copy link

Anyone solved the problem ? I have this erreur after a recent apt-get update on my server.

@eliecharra
Copy link

up

@dmaicher
Copy link
Contributor

I just downloaded and compiled libpcre 8.37 and the swiftmailer regex works just fine using pcregrep. So I think the issue is more likely to be with php or apache2 itself? Some weird libpcre mismatch or something... not sure :(

@liayn
Copy link

liayn commented May 25, 2015

Just a hint from the TYPO3 world: https://forge.typo3.org/issues/67048

We face the same issue. Affected PHP versions seem to be 5.6.9, 5.5.25 and 5.4.41
This bug crashes the whole template engine Fluid in our case!

@xdecock
Copy link
Member

xdecock commented May 26, 2015

Nice job altough hard to fix from here :(

But swift 6 will work with emailchecker
Le 26 mai 2015 12:04 AM, "Markus Klein" notifications@github.com a écrit :

Just a hint from the TYPO3 world: https://forge.typo3.org/issues/67048

We face the same issue. Affected PHP versions seem to be 5.6.9, 5.5.25 and
5.4.41
This bug crashes the whole template engine Fluid in our case!


Reply to this email directly or view it on GitHub
#259 (comment)
.

@mzur
Copy link

mzur commented May 26, 2015

To check if you have mismatching versions of PCRE between the system library and PHP you can run pcretest -C and php -i | grep PCRE. If the versions don't match, this is likely the cause of the error.

I'll ask the support of my hoster what exactly they did to make the versions match and report back later.

@liayn
Copy link

liayn commented May 26, 2015

As noted in https://bugs.php.net/bug.php?id=69689 obviously they messed up the version number as well and PHP reports a wrong version number.

@mzur
Copy link

mzur commented May 26, 2015

My hoster solved the version mismatch by rebuilding PHP using the configure script with --with-pcre-regex=/usr. A PHP upgrade might fix this issue as well.

@sangar82
Copy link

My hoster solves the situation downgrading the php version to 5.5.24, the last was 5.5.25
You pointed us to the right direction. Good work!.

@samwierema
Copy link

Seems to have been fixed in source: php/php-src@f38ca75

@JanTvrdik
Copy link

Can anyone confirm this has been resolved with the latest snapshot?

@gnutix
Copy link

gnutix commented Jun 5, 2015

I just hit the same bug today using PHP 5.5.25-1dotdeb+7.1 and PHP 5.6.9-1dotdeb+7.2.
Removing dotdeb and using PHP 5.4.41-0+deb7u1 works.

@dseguy
Copy link

dseguy commented Jun 10, 2015

Thanks to this threads I fixed a similar problem in my WP installation.

@xkobal
Copy link

xkobal commented Jun 12, 2015

Same with 5.6.10 from dotdeb

@xdecock
Copy link
Member

xdecock commented Jun 12, 2015

And 5.6.9 ? Or a self build ? It was an error in packaging basically the
bundled pcrelib is only partially updated

Le ven. 12 juin 2015 14:14, Xavier HAUSHERR notifications@github.com a
écrit :

Same with 5.5.25 and 5.6.10 from dotdeb


Reply to this email directly or view it on GitHub
#259 (comment)
.

@xkobal
Copy link

xkobal commented Jun 12, 2015

Seems to be a packaging bug indeed:

root@jfg-stage-internal-1:# php -v
PHP 5.6.10-1
dotdeb+7.1 (cli) (built: Jun 11 2015 20:38:39)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
root@jfg-stage-internal-1:~# php -i | grep PCRE
PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.36 2014-09-26

PHP changelog show 8.37...

@xdecock
Copy link
Member

xdecock commented Jun 12, 2015

It's not the first time unfortunately and we got the bug reports everytime

Le ven. 12 juin 2015 14:20, Xavier HAUSHERR notifications@github.com a
écrit :

Seems to be a packaging bug indeed:

root@jfg-stage-internal-1:# php -v
PHP 5.6.10-1
dotdeb+7.1 (cli) (built: Jun 11 2015 20:38:39)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies
root@jfg-stage-internal-1:~# php -i | grep PCRE
PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.36 2014-09-26

PHP changelog show 8.37...


Reply to this email directly or view it on GitHub
#259 (comment)
.

@gplessis
Copy link

It's not a packaging issue, PCRE_MINOR hasn't been changed correctly in PHP upstream. I'm currently building packages of PHP 5.6, 5.5 and 5.4 with this cosmetic change. Stay tuned.

gplessis/dotdeb-php@f3749b7

BTW, that's just a cosmetic change, not sure if it solves your original issue. Please keep me posted.

@gplessis
Copy link

Guys, I just uploaded new PHP 5.6 packages (versions 5.6.10-1~dotdeb+7.2 and 5.6.10-1~dotdeb+zts+7.2). Could you please confirm that PCRE 8.37 is displayed? If so, does it fixes your original issue?

@dmaicher
Copy link
Contributor

Thx for the update. Now the version looks correct:

php -v
PHP 5.6.10-1~dotdeb+7.2 (cli) (built: Jun 13 2015 20:08:39) 

php -i | grep PCRE
PCRE Library Version => 8.37 2015-04-28

Unfortunately the original problem with the swiftmailer regex using apache2 mod php stays the same :(

@gplessis
Copy link

I just uploaded new PHP 5.6 packages (versions 5.6.10-1dotdeb+7.3 and 5.6.10-1dotdeb+zts+7.3) that fix your issue.

@Zeromax
Copy link

Zeromax commented Jun 16, 2015

@gplessis thanks, this fixed it for me.

@dseguy
Copy link

dseguy commented Jun 18, 2015

Thanks @gplessis. Works wonder here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests