Skip to content
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

PCRE regex validation problem for pcre8 mode #425

Closed
pkorsukov opened this issue May 25, 2015 · 7 comments
Closed

PCRE regex validation problem for pcre8 mode #425

pkorsukov opened this issue May 25, 2015 · 7 comments

Comments

@pkorsukov
Copy link

On my production environment PHPMailer suddenly stopped sending the messages.
The error in PHPMailer:
preg_match(): Compilation failed: internal error: previously-checked referenced subpattern not found at offset 728
which comes from validateAddress function after case 'pcre8'.

After the research I found that it can be related to PCRE library update. The environment is Debian+Apache+PHP5+PCRE 8.36.

There was no solution for me, so I force $patternselect = 'pcre'; and now it is working.
It would be great to take a look why pcre8 regex is not compatible with the recent version of PCRE.
Thanks!

@Synchro
Copy link
Member

Synchro commented May 26, 2015

Can you post an example of an address that triggers this? There is a fix in PCRE 8.37 for a bug in 8.36 that generates this error, so it may be that.

@pkorsukov
Copy link
Author

In my case it was for all e-mail addresses of our new users. Something like
user@test-domain.com throws exception

@bizley
Copy link

bizley commented May 26, 2015

For me it was typical email address: test@test1.com

@Synchro
Copy link
Member

Synchro commented May 26, 2015

I'm having no trouble with these addresses with PCRE 8.36 in PHP 5.6.9 and the 'pcre8' pattern, so it seems there must be an environmental factor involved. It sounds like it might be similar to the problems that arose before PCRE 8.03. It's tempting to dump those custom patterns altogether and just use the PHP filter_var one since it's almost identical.

FWIW, the test suite on Travis-CI runs all the same validation checks using PHP 5.3, 5.4, 5.5, 5.6 and 7 and none have been failing there.

@pkorsukov
Copy link
Author

For me the validation is not important at all, so I would prefer to have a component which always works without any version-specific functions. Especially when it comes to mail function which popular across the community.
Please consider removing the pcre8 mode as soon as it have no impact on security but impacting the stability.

@Synchro
Copy link
Member

Synchro commented May 26, 2015

I've just given this a try. Reverting to the php or pcre validators results in more failures than I thought - neither accepts quoted names, IPv6 literals or comments in addresses, all of which are valid and not entirely uncommon. I don't think it's reasonable to change this behaviour so much in order to deal with an edge case that can be worked around so easily. Bear in mind that all the version-specific stuff that's already there is to deal with scenarios where PHP simply doesn't have an appropriate function and is necessary to provide a consistent interface across so many PHP versions. Just to be clear, all you need to do is this:

class myMailer extends PHPMailer {
    public static function validateAddress($address, $patternselect = 'php')
    {
        return parent::validateAddress($address, $patternselect);
    }
}

Subclassing is a good habit anyway as it provides isolation between a specific implementation and your app code - I do this nearly everywhere I use PHPMailer.

If you want to take this further, you could report this to the author of the pcre8 pattern here.

@Synchro Synchro closed this as completed May 26, 2015
@Synchro
Copy link
Member

Synchro commented Jun 1, 2015

It appears that this is a PHP bug affecting PHP version 5.5.25 and 5.6.9 when run as an apache handler (i.e. mod_php), see #429, which is actually a duplicate of this issue.

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

No branches or pull requests

3 participants