PHP is trying to allocate 127 TB of memory and memory leaks with preg_match and preg_replace

I think I discovered a problem that seems to be creating a memory leak in Apache / PHP when Unicode characters are delimiters or sometimes somewhere in the regex with preg_matchand preg_replace. Perhaps this happens in more than preg_*methods.

Test case 1

Create a new PHP file test.phpwith the following contents:

<?php
    preg_match( '°test°i', 'test', $matches );

Test case 2

Create a new PHP file test.phpwith the following contents:

<?php
    preg_match( '°', 'test', $matches );

The unicode character °used as the delimiter is the power sign. Try any other Unicode character to see what happens if you want.

Result

- Apache 2.4.10 (Debian) PHP 5.6.0-1+b1, . " " " ".

Apache error.log(/var/log/error.log):

[Mon Dec 15 10:31:09.941622 2014] [:error] [pid 6292] [client ###.###.###.###:64413] PHP Warning:  preg_match():  in /path/to/test.php on line 2
[Mon Dec 15 10:31:09.941796 2014] [:error] [pid 6292] [client ###.###.###.###:64413] PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 139979759686648 bytes) in Unknown on line 0

, , PHP , 127 .

Apache

PHP- script , , . , , , , :

Class MyClass not found in file MyExtendingClass.php on Line 3

MyExtendingClass.php :

<?php
    class MyExtendingClass extends MyClass
    {
    }

, MyClass 2, , PHP .

, Unicode . PHP Unicode? ? , PHP , .

Apache/2.4.10 (Debian) PHP/5.6.0-1 + b1 OpenSSL/1.0.1i

+3
1

, PHP RAM - slighlty 127 , script.

PHP Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to allocate 140683487706824 bytes) in Unknown on line 0

PHP- 5.4.39-0 + deb7u2, , script, script . script , , script.

, , dblib + freetds MSSQL, Debian, # 64511. , .

- , .

  • MSSQL
  • ( , SELECT )

, - :

$sprocResultSet = $PDOquery->fetchAll(PDO::FETCH_ASSOC);
$PDOquery->nextRowset();
$sprocExitCode = $PDOquery->fetchAll(PDO::FETCH_ASSOC);

, .

, fetchAll(), setFetchMode(), :

$PDOquery->setFetchMode(PDO::FETCH_ASSOC);
$sprocResultSet = $PDOquery->fetchAll();
$PDOquery->nextRowset();
$sprocExitCode = $PDOquery->fetchAll();

.

$PDOquery script end - . , , - sproc, SELECT , , , .

... , , , , PDO.

, . -, PDO nextResultSet(), , : nextRowset . -, PDO fetch() , , , DBLIB.

+1

All Articles