php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62384 Attempting to invoke a Closure more than once causes segfault
Submitted: 2012-06-21 23:08 UTC Modified: 2012-06-22 15:08 UTC
From: alexander dot carver at gmail dot com Assigned: felipe
Status: Closed Package: Reflection related
PHP Version: 5.3.14 OS: Debian 6.0
Private report: No CVE-ID:
 [2012-06-21 23:08 UTC] alexander dot carver at gmail dot com
Description:
------------
The code below should be fairly self-explanatory. Invoking a reflection of the 
__invoke method of the Closure class more than once per reflection instance 
causes a segfault. This happens regardless of context or argument parameters 
passed to ReflectionMethod::invokeArgs(). Can't imagine this is a common use case 
but thought I'd share anyway.

PHP Version is 5.3.14.

I don't have php configured to get a backtrace at the moment, and my .ini is 
pretty average. If you can't reproduce it with the script below I'll look into it 
more.

php5 -m :

[PHP Modules]
apc
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
mhash
mysql
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
SQLite
sqlite3
ssh2
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xdebug
xml
xmlreader
xmlwriter
yaml
zip
zlib

[Zend Modules]
Xdebug

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

$closure1   = function($val){ return $val; };
$closure2   = function($val){ return $val; };

$reflection_class   = new ReflectionClass($closure1);
$reflection_method  = $reflection_class->getMethod('__invoke');

$arguments1         = array('hello');
$arguments2         = array('world');

// Invoking once is OK...
print $reflection_method->invokeArgs($closure1, $arguments1);

if(true){   
    // But don't do it again!
   #print $reflection_method->invokeArgs($closure1, $arguments1);
    
    // Using different arguments per invokation makes no difference :(
   #print $reflection_method->invokeArgs($closure1, $arguments2);
    
    // Doesn't matter if you attempt to invoke a different closure with the same reflection.
    print $reflection_method->invokeArgs($closure2, $arguments1);
}

?>

Expected result:
----------------
"helloworld" printed

Actual result:
--------------
Segmentationfault

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-21 23:10 UTC] alexander dot carver at gmail dot com
-PHP Version: 5.4.4 +PHP Version: 5.3.14
 [2012-06-21 23:10 UTC] alexander dot carver at gmail dot com
Wrong version number, sorry.
 [2012-06-22 02:19 UTC] Reeze dot xia at gmail dot com
Can you reproduce it when apc and xdebug disabled´╝č
 [2012-06-22 06:37 UTC] alexander dot carver at gmail dot com
Yes I can.

php5 -m :
[PHP Modules]
bcmath bz2
calendar Core ctype curl
date dba dom
ereg exif
fileinfo filter ftp
gd gettext
hash
iconv
json
libxml
mbstring mhash mysql mysqli mysqlnd
openssl
pcntl pcre PDO pdo_mysql pdo_sqlite Phar posix
readline Reflection
session shmop SimpleXML soap sockets SPL
SQLite sqlite3 ssh2 standard
sysvmsg sysvsem sysvshm
tokenizer
wddx
xml xmlreader xmlwriter
yaml
zip
zlib

[Zend Modules]
 [2012-06-22 14:46 UTC] felipe@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: felipe
 [2012-06-22 15:07 UTC] felipe@php.net
Automatic comment on behalf of felipensp@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b8e946b02eac53f46cbfc8eefb5c91fb5b075c9d
Log: - Fixed bug #62384 (Attempting to invoke a Closure more than once causes segfaul)
 [2012-06-22 15:08 UTC] felipe@php.net
-Status: Assigned +Status: Closed
 [2012-06-22 15:08 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-06-22 19:53 UTC] alexander dot carver at gmail dot com
That was fast! No problem, happy to help. Thanks for all your work!
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 06:02:27 2014 UTC