php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81198 preg_match doesn't work properly
Submitted: 2021-06-23 19:43 UTC Modified: 2021-07-04 04:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: advocat at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: PCRE related
PHP Version: 7.4.20 OS: OSX Big Sur
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-06-23 19:43 UTC] advocat at gmail dot com
Description:
------------
From manual page: https://php.net/function.preg-match

---

PHP 7.4.20 (cli) (built: Jun  4 2021 03:32:07) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.20, Copyright (c), by Zend Technologies

Test script:
---------------
$pattern  = "#/(?<moduleName>[^/]+)/layout/[^/]*\.xml$#i";
$filename = "/var/www/project/vendor/magento/theme-frontend-blank/Magento_Theme/layout/default_head_blocks.xml";

var_dump(preg_match($pattern, $filename, $matches), $matches);

$pattern  = "#/([^/]+)/layout/[^/]*\.xml$#i";

var_dump(preg_match($pattern, $filename, $matches), $matches);

Expected result:
----------------
int(1)
array(3) {
  [0]=>
  string(45) "/Magento_Theme/layout/default_head_blocks.xml"
  ["moduleName"]=>
  string(13) "Magento_Theme"
  [1]=>
  string(13) "Magento_Theme"
}
int(1)
array(2) {
  [0]=>
  string(45) "/Magento_Theme/layout/default_head_blocks.xml"
  [1]=>
  string(13) "Magento_Theme"
}

Actual result:
--------------
int(0)
array(0) {
}
int(0)
array(0) {
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-06-23 20:10 UTC] danack@php.net
Please try disabling pcre.jit with `ini_set("pcre.jit", "0")`

possibly dupe of
https://bugs.php.net/bug.php?id=81185
 [2021-06-23 20:11 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2021-06-23 20:11 UTC] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves.

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external
resources such as databases, etc. If the script requires a
database to demonstrate the issue, please make sure it creates
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

https://3v4l.org/4YDGj

If you've tried *that exact code* and it isn't working,
- What version of PCRE2 do you have?
- What if you disable JIT with pcre.jit=0?
 [2021-06-23 20:13 UTC] imsop@php.net
Your example script gives the expected output everywhere I've tried it, e.g. https://3v4l.org/4YDGj

Please can you double check, and if you can reproduce with this exact script, provide the PCRE section of the output from phpinfo()
 [2021-06-23 20:15 UTC] imsop@php.net
Oops, didn't see this had already been commented on, apologies for the repeat.
 [2021-06-23 20:59 UTC] advocat at gmail dot com
-Status: Feedback +Status: Open
 [2021-06-23 20:59 UTC] advocat at gmail dot com
This is reproduce on OS Big Sur x64 (looks like OS specific)
I've tried to use compiled version from homebrew and tried to build from source
Some interesting cases:

---
$ php -i | grep pcre
Configure Command =>  './configure'  '--prefix=/usr/local/Cellar/php@7.4/7.4.20' '--localstatedir=/usr/local/var' '--sysconfdir=/usr/local/etc/php/7.4' '--with-config-file-path=/usr/local/etc/php/7.4' '--with-config-file-scan-dir=/usr/local/etc/php/7.4/conf.d' '--with-pear=/usr/local/Cellar/php@7.4/7.4.20/share/php@7.4/pear' '--enable-bcmath' '--enable-calendar' '--enable-dba' '--enable-exif' '--enable-ftp' '--enable-fpm' '--enable-gd' '--enable-intl' '--enable-mbregex' '--enable-mbstring' '--enable-mysqlnd' '--enable-pcntl' '--enable-phpdbg' '--enable-phpdbg-readline' '--enable-phpdbg-webhelper' '--enable-shmop' '--enable-soap' '--enable-sockets' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--with-apxs2=/usr/local/opt/httpd/bin/apxs' '--with-bz2=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr' '--with-curl' '--with-external-gd' '--with-external-pcre' '--with-ffi' '--with-fpm-user=_www' '--with-fpm-group=_www' '--with-gettext=/usr/local/opt/gettext' '--with-gmp=/usr/local/opt/gmp' '--with-iconv=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr' '--with-kerberos' '--with-layout=GNU' '--with-ldap=/usr/local/opt/openldap' '--with-libxml' '--with-libedit' '--with-mhash=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr' '--with-mysql-sock=/tmp/mysql.sock' '--with-mysqli=mysqlnd' '--with-ndbm=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr' '--with-openssl' '--with-password-argon2=/usr/local/opt/argon2' '--with-pdo-dblib=/usr/local/opt/freetds' '--with-pdo-mysql=mysqlnd' '--with-pdo-odbc=unixODBC,/usr/local/opt/unixodbc' '--with-pdo-pgsql=/usr/local/opt/libpq' '--with-pdo-sqlite' '--with-pgsql=/usr/local/opt/libpq' '--with-pic' '--with-pspell=/usr/local/opt/aspell' '--with-sodium' '--with-sqlite3' '--with-tidy=/usr/local/opt/tidy-html5' '--with-unixODBC' '--with-xmlrpc' '--with-xsl' '--with-zip' '--with-zlib' '--enable-dtrace' '--with-ldap-sasl' '--with-os-sdkpath=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' 'PKG_CONFIG_PATH=/usr/local/opt/apr/lib/pkgconfig:/usr/local/opt/openssl@1.1/lib/pkgconfig:/usr/local/opt/argon2/lib/pkgconfig:/usr/local/opt/brotli/lib/pkgconfig:/usr/local/opt/libidn2/lib/pkgconfig:/usr/local/opt/libmetalink/lib/pkgconfig:/usr/local/opt/libssh2/lib/pkgconfig:/usr/local/opt/c-ares/lib/pkgconfig:/usr/local/opt/jemalloc/lib/pkgconfig:/usr/local/opt/nghttp2/lib/pkgconfig:/usr/local/opt/openldap/lib/pkgconfig:/usr/local/opt/rtmpdump/lib/pkgconfig:/usr/local/opt/zstd/lib/pkgconfig:/usr/local/opt/curl/lib/pkgconfig:/usr/local/opt/unixodbc/lib/pkgconfig:/usr/local/opt/libpng/lib/pkgconfig:/usr/local/opt/freetype/lib/pkgconfig:/usr/local/opt/fontconfig/lib/pkgconfig:/usr/local/opt/jpeg/lib/pkgconfig:/usr/local/opt/libtiff/lib/pkgconfig:/usr/local/opt/webp/lib/pkgconfig:/usr/local/opt/gd/lib/pkgconfig:/usr/local/opt/libffi/lib/pkgconfig:/usr/local/opt/pcre/lib/pkgconfig:/usr/local/opt/readline/lib/pkgconfig:/usr/local/opt/sqlite/lib/pkgconfig:/usr/local/opt/xz/lib/pkgconfig:/usr/local/opt/python@3.9/lib/pkgconfig:/usr/local/opt/glib/lib/pkgconfig:/usr/local/opt/gmp/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig:/usr/local/opt/krb5/lib/pkgconfig:/usr/local/opt/libpq/lib/pkgconfig:/usr/local/opt/libsodium/lib/pkgconfig:/usr/local/opt/libzip/lib/pkgconfig:/usr/local/opt/oniguruma/lib/pkgconfig:/usr/local/opt/pcre2/lib/pkgconfig:/usr/local/opt/tidy-html5/lib/pkgconfig' 'PKG_CONFIG_LIBDIR=/usr/lib/pkgconfig:/usr/local/Homebrew/Library/Homebrew/os/mac/pkgconfig/11' 'KERBEROS_CFLAGS= ' 'SASL_CFLAGS=-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sasl' 'SASL_LIBS=-lsasl2'
pcre
pcre.backtrack_limit => 1000000 => 1000000
pcre.jit => 1 => 1
pcre.recursion_limit => 100000 => 100000
---

I've tried to play with values and now the script

---
<?php

$pattern  = "#/(?<moduleName>[^/]+)/layout/[^/]*\.xml$#i";
$filename = "/var/www/project/vendor/magento/theme-frontend-blank/Magento_Theme/layout/default_head_blocks.xml";

var_dump(preg_match($pattern, $filename, $matches), $matches);

$filename = "/var/www/project/name/vendor/magento/theme-frontend-blank/Magento_Theme/layout/default_head_blocks.xml";

var_dump(preg_match($pattern, $filename, $matches), $matches);
---


Outputs
---
int(1)
array(3) {
  [0]=>
  string(45) "/Magento_Theme/layout/default_head_blocks.xml"
  ["moduleName"]=>
  string(13) "Magento_Theme"
  [1]=>
  string(13) "Magento_Theme"
}
int(0)
array(0) {
}
---

I cannot reproduce the issue with 3v4l
 [2021-06-23 21:08 UTC] advocat at gmail dot com
When i force disabled pcre.jit in config - looks like this is solve the issue
I spent a lot of time to identify which one logic stopped to work

BIG Thank you
 [2021-06-25 16:12 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2021-06-25 16:12 UTC] cmb@php.net
> When i force disabled pcre.jit in config - looks like this is
> solve the issue

Great! Which PCRE version do you use?

    <?php echo PCRE_VERSION ?;
 [2021-07-04 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 23 02:01:29 2024 UTC