Bug #77300 [NEW]: Incorrect preg_replace_callback() result when using FILTER_VALIDATE_REGEXP
From: phpwnd at gmail dot com
Operating system: Gentoo
PHP version: 7.3.0
Package: PCRE related
Bug Type: Bug
Bug description:Incorrect preg_replace_callback() result when using FILTER_VALIDATE_REGEXP
Description:
------------
I'm getting incorrect results from preg_replace_callback() on PHP 7.3.0
when it fulfills the following conditions:
- preg_replace_callback's input must contain at least 2 matches.
- preg_replace_callback's callback must call filter_var() with
FILTER_VALIDATE_REGEXP and filter_var's regexp must match its input.
From what I can tell, preg_replace_callback() keeps looping through
matches internally (it requires at least 2 matches to trigger) and keeps
doing replacements until it reaches its match limit or runs out of
resources.
I wasn't able to reproduce this behaviour on a secondary machine, so
there may be a platform-specific component to it. No issue on PHP 7.2.x
--------------------
PHP 7.3.0 (cli) (built: Dec 13 2018 08:57:16) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies
Configure Command => './configure' '--prefix=/usr'
'--build=x86_64-pc-linux-gnu' '--host=x86_64-pc-linux-gnu'
'--mandir=/usr/share/man' '--infodir=/usr/share/info'
'--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib'
'--docdir=/usr/share/doc/php-7.3.0'
'--htmldir=/usr/share/doc/php-7.3.0/html' '--prefix=/usr/lib64/php7.3'
'--mandir=/usr/lib64/php7.3/man' '--infodir=/usr/lib64/php7.3/info'
'--libdir=/usr/lib64/php7.3/lib' '--with-libdir=lib64'
'--localstatedir=/var' '--without-pear' '--disable-maintainer-zts'
'--with-password-argon2=/usr' '--disable-bcmath' '--without-bz2'
'--disable-calendar' '--disable-gcov' '--enable-ctype'
'--with-curl=/usr' '--enable-dom' '--without-enchant'
'--disable-exif'
'--enable-fileinfo' '--enable-filter' '--disable-ftp'
'--without-gettext' '--without-gmp' '--enable-hash'
'--without-mhash'
'--with-iconv' '--enable-intl' '--disable-ipv6'
'--enable-json'
'--without-kerberos' '--enable-libxml' '--with-libxml-dir=/usr'
'--enable-mbstring' '--with-onig=/usr' '--with-openssl=/usr'
'--with-openssl-dir=/usr' '--disable-pcntl' '--enable-phar'
'--enable-pdo' '--enable-opcache' '--without-pgsql'
'--disable-posix'
'--without-pspell' '--without-recode' '--enable-simplexml'
'--disable-shmop' '--without-snmp' '--disable-soap'
'--disable-sockets'
'--without-sodium' '--with-sqlite3=/usr' '--disable-sysvmsg'
'--disable-sysvsem' '--disable-sysvshm' '--without-tidy'
'--enable-tokenizer' '--disable-wddx' '--enable-xml'
'--enable-xmlreader' '--enable-xmlwriter' '--with-xmlrpc'
'--with-xsl=/usr' '--enable-zip' '--without-libzip'
'--with-zlib=/usr'
'--disable-debug' '--enable-dba' '--without-cdb'
'--without-db4'
'--disable-flatfile' '--without-gdbm' '--enable-inifile'
'--without-qdbm' '--without-lmdb' '--without-freetype-dir'
'--disable-gd-jis-conv' '--with-jpeg-dir=/usr' '--with-png-dir=/usr'
'--without-xpm-dir' '--with-gd' '--without-interbase'
'--with-mysqli=mysqlnd' '--with-mysql-sock=/var/run/mysqld/mysqld.sock'
'--without-unixODBC' '--without-iodbc' '--without-oci8'
'--without-pdo-dblib' '--with-pdo-mysql=mysqlnd' '--without-pdo-pgsql'
'--with-pdo-sqlite=/usr' '--without-pdo-firebird' '--without-pdo-odbc'
'--without-pdo-oci' '--with-readline=/usr' '--without-libedit'
'--without-mm' '--with-pic' '--with-pcre-regex=/usr'
'--with-pcre-dir=/usr' '--without-pcre-valgrind' '--without-pcre-jit'
'--cache-file=/var/tmp/portage/dev-lang/php-7.3.0/temp/config.cache'
'--with-config-file-path=/etc/php/cli-php7.3'
'--with-config-file-scan-dir=/etc/php/cli-php7.3/ext-active'
'--disable-embed' '--enable-cli' '--disable-cgi'
'--disable-fpm'
'--without-apxs2' '--disable-phpdbg' 'build_alias=x86_64-pc-linux-gnu'
'host_alias=x86_64-pc-linux-gnu' 'CPPFLAGS='
PCRE Library Version => 10.32 2018-09-10
PCRE Unicode Version => 11.0.0
PCRE JIT Support => not compiled in
pcre.backtrack_limit => 1000000 => 1000000
pcre.recursion_limit => 100000 => 100000
Test script:
---------------
<?php
function cb()
{
filter_var('', FILTER_VALIDATE_REGEXP, ['options' => ['regexp'
=>
'//']]);
return '.';
}
var_dump(preg_replace_callback('/./', 'cb', 'xx', 10));
Expected result:
----------------
string(2) ".."
Actual result:
--------------
string(12) "..........xx"
--
Edit bug report at https://bugs.php.net/bug.php?id=77300&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=77300&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=77300&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=77300&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=77300&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=77300&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=77300&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=77300&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=77300&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=77300&r=support
Expected behavior: https://bugs.php.net/fix.php?id=77300&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=77300&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=77300&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=77300&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=77300&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=77300&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=77300&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=77300&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=77300&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=77300&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=77300&r=mysqlcfg
Thread (1 message)
- phpwnd at gmail dot com