php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81101 PCRE2 10.37 shows unexpected result
Submitted: 2021-06-03 14:19 UTC Modified: 2021-06-19 19:31 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (100.0%)
From: rlanting at move4mobile dot com Assigned: ab (profile)
Status: Closed Package: PCRE related
PHP Version: 8.0.6 OS: MacOS 11.3.1
Private report: No CVE-ID: None
 [2021-06-03 14:19 UTC] rlanting at move4mobile dot com
Description:
------------
This week I updated php and pcre through homebrew. As a result I got pcre2 10.37. For that specific version preg_match doesn't work as expected. Reverting only pcre2 to 10.36 makes it work again.

The regex originates from https://github.com/phpspec/phpspec/blob/eb0d939b235f6091a8439a2a2fc144c9e0d5f569/src/PhpSpec/CodeAnalysis/TokenizedNamespaceResolver.php#L119

Homebrew issue: https://github.com/Homebrew/homebrew-core/issues/78635

Test script:
---------------
<?php

$matches = [];
$test = ' App\Domain\Repository\MetaData\SomethingRepositoryInterface';

preg_match('/\\\\([^\\\\]+)\s*$/', $test, $matches);
var_dump($matches);

$test2 = ' App\Domain\Exception\NotFoundException';

preg_match('/\\\\([^\\\\]+)\s*$/', $test2, $matches);
var_dump($matches);

Expected result:
----------------
array(2) {
  [0]=>
  string(29) "\SomethingRepositoryInterface"
  [1]=>
  string(28) "SomethingRepositoryInterface"
}
array(2) {
  [0]=>
  string(18) "\NotFoundException"
  [1]=>
  string(17) "NotFoundException"
}

Actual result:
--------------
array(0) {
}
array(2) {
  [0]=>
  string(18) "\NotFoundException"
  [1]=>
  string(17) "NotFoundException"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-03 14:25 UTC] rlanting at move4mobile dot com
As an additional note, I tried reproducing with the pcre2test binary but couldn't get it to break with that.
 [2021-06-03 14:40 UTC] Danack at basereality dot com
As a simple thing to check, please could you set ini_set("pcre.jit", "0"); to see if that makes any difference on the broken version.
 [2021-06-03 14:41 UTC] nikic@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: ab
 [2021-06-03 14:41 UTC] nikic@php.net
Can reproduce on master, where bundled PCRE is 10.37. It does not reproduce with -d pcre.jit=0, so this is clearly a PCRE JIT bug.

Assigning to @ab as he did the upgrade of the bundled version, but in the end this will need an upstream report and fix.
 [2021-06-04 06:59 UTC] rlanting at move4mobile dot com
PCRE bug report: https://bugs.exim.org/show_bug.cgi?id=2763
 [2021-06-04 12:06 UTC] ab@php.net
-Status: Verified +Status: Analyzed
 [2021-06-04 12:06 UTC] ab@php.net
Thanks for filing the upstream report. The offending commit is

https://vcs.pcre.org/pcre2?view=revision&revision=1302

It'd be still better if it were fixable on our side, as 10.37 is already out. I'll see for that.

Thanks
 [2021-06-04 13:51 UTC] rlanting at move4mobile dot com
Upstream has fixed it in r1315:

https://vcs.pcre.org/pcre2?view=revision&revision=1315
 [2021-06-06 23:56 UTC] ab@php.net
I pushed a potential fix to master. I'd suggest to observe for a week or two and backport into 7.4+ if it goes ok.

Thanks.
 [2021-06-19 19:31 UTC] ab@php.net
-Status: Analyzed +Status: Closed
 [2021-06-19 19:31 UTC] ab@php.net
The mitigation patch backported to 7.4 and 8.0.

Thanks
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 27 23:03:36 2021 UTC