From: matej21 at matej21 dot cz
Operating system:
PHP version: 7.0.2
Package: SPL related
Bug Type: Bug
Bug description:Segfault in AppendIterator with empty generator
Description:
------------
AppendIterator produces a segfault when it iterates over an empty
generator.
https://3v4l.org/q3I67
Test script:
---------------
<?php
function foo() {
foreach ([] as $foo) {
yield $foo;
}
}
$iterator = new AppendIterator();
$iterator->append(foo());
var_dump(iterator_to_array($iterator));
Expected result:
----------------
array(0) {
}
Actual result:
--------------
Program received signal SIGSEGV, Segmentation fault.
#0 spl_dual_it_rewind (intern=0x7fffed2783c0) at
/usr/local/src/php/ext/spl/spl_iterators.c:1682
#1 spl_append_it_next_iterator (intern=intern@entry=0x7fffed2783c0) at
/usr/local/src/php/ext/spl/spl_iterators.c:3332
#2 0x000000000071fff4 in zim_spl_AppendIterator_rewind
(execute_data=<optimized out>, return_value=<optimized out>) at
/usr/local/src/php/ext/spl/spl_iterators.c:3403
#3 0x00000000008157df in zend_call_function
(fci=fci@entry=0x7fffffffa410, fci_cache=fci_cache@entry=0x7fffffffa3e0)
at /usr/local/src/php/Zend/zend_execute_API.c:879
#4 0x000000000083ec54 in zend_call_method
(object=object@entry=0x7fffed2691f8, obj_ce=<optimized out>,
fn_proxy=0x1287000, function_name=function_name@entry=0x989d4c "rewind",
function_name_len=function_name_len@entry=6,
retval_ptr=retval_ptr@entry=0x0, param_count=param_count@entry=0,
arg1=arg1@entry=0x0, arg2=arg2@entry=0x0) at
/usr/local/src/php/Zend/zend_interfaces.c:104
#5 0x000000000083f25a in zend_user_it_rewind (_iter=0x7fffed2691c0) at
/usr/local/src/php/Zend/zend_interfaces.c:245
#6 0x0000000000720212 in spl_iterator_apply (obj=<optimized out>,
apply_func=0x719ae0 <spl_iterator_to_array_apply>,
puser=puser@entry=0x7fffed2130f0) at
/usr/local/src/php/ext/spl/spl_iterators.c:3503
#7 0x00000000007202e5 in zif_iterator_to_array (execute_data=<optimized
out>, return_value=0x7fffed2130f0) at
/usr/local/src/php/ext/spl/spl_iterators.c:3590
#8 0x000000000089c12b in ZEND_DO_FCALL_SPEC_HANDLER () at
/usr/local/src/php/Zend/zend_vm_execute.h:842
#9 0x000000000085ed3b in execute_ex (ex=<optimized out>) at
/usr/local/src/php/Zend/zend_vm_execute.h:414
#10 0x00000000008a7c27 in zend_execute (op_array=0x7fffed283000,
op_array@entry=0x7fffed288180,
return_value=return_value@entry=0x7fffed213030) at
/usr/local/src/php/Zend/zend_vm_execute.h:458
#11 0x0000000000823494 in zend_execute_scripts (type=type@entry=8,
retval=0x7fffed213030, retval@entry=0x0, file_count=file_count@entry=3)
at /usr/local/src/php/Zend/zend.c:1427
#12 0x00000000007c7698 in php_execute_script
(primary_file=primary_file@entry=0x7fffffffc9c0) at
/usr/local/src/php/main/main.c:2484
#13 0x00000000008a97f3 in do_cli (argc=2, argv=0x119cc10) at
/usr/local/src/php/sapi/cli/php_cli.c:974
#14 0x000000000044d9e0 in main (argc=2, argv=0x119cc10) at
/usr/local/src/php/sapi/cli/php_cli.c:1345
--
Edit bug report at https://bugs.php.net/bug.php?id=71436&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71436&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71436&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71436&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71436&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71436&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71436&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71436&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71436&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71436&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71436&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71436&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71436&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71436&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71436&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71436&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71436&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71436&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71436&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71436&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71436&r=mysqlcfg