Bug #74015 [NEW]: ReflectionClass::getInterfaceNames wrong entry with random memory location
| From: | uli dot hecht at gmail dot com | Date: | Mon, 30 Jan 2017 13:41:26 +0000 |
| Subject: | Bug #74015 [NEW]: ReflectionClass::getInterfaceNames wrong entry with random memory location | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-207042@lists.php.net to get a copy of this message | ||
From: uli dot hecht at gmail dot com
Operating system: Windows
PHP version: 7.1.1
Package: opcache
Bug Type: Bug
Bug description:ReflectionClass::getInterfaceNames wrong entry with random memory location
Description:
------------
This bug only appears on my Windows system and is very hard to
reproduce. I can only reproduce it with Symfony-projects, however all of
my Symfony projects are affected. It seems that the problem doesn't
occur, as long as Opcache is disabled:
After loading the page in the browser about 5 to 10 times, entries of
the result array of ReflectionClass::getInterfaceNames() contain
unexpected data. As soon as the error appears, getInterfaceNames() will
return the same (wrong) data for the same interface on every succeeding
call, no matter which class is reflected.
For instance, today "\Serializable" has been affected. Instead of
"\Serializable", getInterfaceNames() returned an entry containing
"#[^/\\]*$#" everytime for a Symfony class implementing that interface.
I defined an own class implementing \Serialiazable (see test script) to
check this, and got the same result:
array(1) { [0]=> string(10) "#[^/\\]*$#" }
I'm running PHP as Apache 2.4 module. The error disappears, as soon as I
restart the HTTP server. Then I have another 5 to 10 reloads until the
problem re-appears with other interfaces being affected and other wrong
random values being returned for those affected interfaces.
In 95% of the cases an "OutOfMemoryException" is thrown, because the
string length is a few Gigabytes, making it difficult to determine the
affected interface. For example, at the moment I'm writing this,
"\IteratorAggregate" is the affected interface and I'm getting this
output:
array(2) { [0]=> string(4294967296) "
Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to
allocate 4294971392 bytes) in
C:\Daten\Projekte\2016\dev\xxxxx-xxxxx\src\web\app_dev.php on line 12
(I just added this information in case somebody is having the same
problems. In the beginning I always googled for OutOfMemoryException
related topics)
Interestingly, in the "\Serializable"-case before, I could find the
string of the corrupt entry ("#[^/\\]*$#") in another Symfony class
variable that has nothing to do with the problem at all. So it seems
that the corrupt entries are pointing to a random location in the
memory.
Note: The test script (obviously) depends on the affected interface. To
find out which interfaces are affected, I have to modify Symfony's
DebugClassLoader temporarily. Symfony crashes here, when processing the
results of getInterfaceNames(). As soon as the error occurs, the test
script can be executed independently from the Symfony project in a
separate PHP file.
This problem is really annoying, because I have to restart my HTTP
server every few page reloads.
My specifications:
- Windows 7 x64
- Apache 2.4.23 win64 VC14 (from apachelounge.com)
- PHP 7.1.1 x64 TS
- Configure line: cscript /nologo configure.js "--enable-snapshot-build"
"--enable-debug-pack"
"--with-pdo-oci=c:\php-sdk\oracle\x64\instantclient_12_1\sdk,shared"
"--with-oci8-12c=c:\php-sdk\oracle\x64\instantclient_12_1\sdk,shared"
"--enable-object-out-dir=../obj/" "--enable-com-dotnet=shared"
"--with-mcrypt=static" "--without-analyzer" "--with-pgo"
I'm having this problem for about a year now, so I can say that also
older PHP7 versions are affected.
php.ini changes (My php.ini is based on php.ini-development):
- I'm using opcache with following php.ini settings:
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
- realpath_cache_size = 2M
- I increased limits (memory, upload file size, execution time, etc.)
- I enabled these extensions: bz2, curl, fileinfo, gs2, intl, mbstring,
mysqli, openssl, pdo_mysql, soap, sockets, redis (only sometimes),
opcache
Test script:
---------------
/* \Serializable being an affected interface */
class DEBUGTEST implements \Serializable {
public function serialize(){}
public function unserialize($serialized){}
}
$drefl = new \ReflectionClass('\DEBUGTEST');
$y = $drefl->getInterfaceNames();
var_dump($y);
die();
/* \IteratorAggregate being an affected interface */
class DEBUGTEST implements \IteratorAggregate {
public function getIterator() {}
}
$drefl = new \ReflectionClass('\DEBUGTEST');
$y = $drefl->getInterfaceNames();
var_dump($y);
die();
--
Edit bug report at https://bugs.php.net/bug.php?id=74015&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74015&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74015&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74015&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74015&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74015&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74015&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74015&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74015&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74015&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74015&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74015&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74015&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74015&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74015&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74015&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74015&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74015&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74015&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74015&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74015&r=mysqlcfg