Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP7.4或8.0大数组 foreach 报Segmentation fault #546

Closed
bobitluo opened this issue Jun 28, 2021 · 7 comments
Closed

PHP7.4或8.0大数组 foreach 报Segmentation fault #546

bobitluo opened this issue Jun 28, 2021 · 7 comments

Comments

@bobitluo
Copy link

laruence 好!报错代码如下:

`<?php
define('APPLICATION_PATH', "/home/bobit/git/yaf_demo");
$application = new \Yaf\Application( APPLICATION_PATH . "/conf/application.ini");
$application->bootstrap();

$data = [];

for($i=0; $i<20000; $i++) {
// $data[] = ['abc']; // 静态字符串时不触发segmentfault
$data[] = [$i];
}

// 注释掉foreach后不触发segmentfault
foreach( $data as $v ){
}
exit( count( $data ) . PHP_EOL );

/*
// for循环不触发segmentfault
$tmp = '';
for( $i=0; $i<count($data); $i++ ){
$tmp .= implode(',', $data[$i]);
}

exit( strlen( $tmp ) . PHP_EOL );
*/`

PHP版本:

PHP 7.4.20 (cli) (built: Jun 1 2021 15:41:56) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies

YAF信息:

`yaf support => enabled
Version => 3.3.2
Supports => http://pecl.php.net/package/yaf

Directive => Local Value => Master Value
yaf.library => no value => no value
yaf.environ => product => product
yaf.forward_limit => 5 => 5
yaf.use_namespace => 1 => 1
yaf.action_prefer => 0 => 0
yaf.lowcase_path => 0 => 0
yaf.use_spl_autoload => 0 => 0
yaf.name_suffix => 1 => 1
yaf.name_separator => no value => no value`

COREDUMP信息:

GNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-120.el7 Copyright (C) 2013 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /usr/bin/php...Reading symbols from /usr/lib/debug/usr/bin/php.debug...done. done. [New LWP 1379] [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". Core was generated by php yaf_segmentfault.php'.
Program terminated with signal 11, Segmentation fault.
#0 0x0000000000000000 in ?? ()
Missing separate debuginfos, use: debuginfo-install bzip2-libs-1.0.6-13.el7.x86_64 cyrus-sasl-lib-2.1.26-23.el7.x86_64 glibc-2.17-260.el7_6.6.x86_64 keyutils-libs-1.5.8-3.el7.x86_64 krb5-libs-1.15.1-37.el7_6.x86_64 libcom_err-1.42.9-13.el7.x86_64 libcurl-7.29.0-51.el7.x86_64 libedit-3.0-12.20121213cvs.el7.x86_64 libgcc-4.8.5-36.el7_6.2.x86_64 libidn-1.28-4.el7.x86_64 libselinux-2.5-14.1.el7.x86_64 libsodium-1.0.18-1.el7.x86_64 libssh2-1.4.3-12.el7_6.2.x86_64 libstdc++-4.8.5-36.el7_6.2.x86_64 libxml2-2.9.1-6.el7_2.3.x86_64 ncurses-libs-5.9-14.20130511.el7_4.x86_64 nspr-4.19.0-1.el7_5.x86_64 nss-3.36.0-7.1.el7_6.x86_64 nss-softokn-freebl-3.36.0-5.el7_5.x86_64 nss-util-3.36.0-1.1.el7_6.x86_64 openldap-2.4.44-21.el7_6.x86_64 openssl-libs-1.0.2k-16.el7_6.1.x86_64 pcre-8.32-17.el7.x86_64 php-pecl-yaf-3.3.2-1.el7.remi.7.4.x86_64 xz-libs-5.2.2-1.el7.x86_64 zlib-1.2.7-18.el7.x86_64
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x0000558ab821614b in gc_mark_grey (stack=0x7ffc5982bc50, ref=0x7fd1b52820f0) at /usr/src/debug/php-7.4.20/Zend/zend_gc.c:828
#2 gc_mark_roots (stack=0x7ffc5982bc50) at /usr/src/debug/php-7.4.20/Zend/zend_gc.c:977
#3 zend_gc_collect_cycles () at /usr/src/debug/php-7.4.20/Zend/zend_gc.c:1452
#4 0x0000558ab82150f8 in gc_possible_root_when_full (ref=0x7fd1aa2a8268) at /usr/src/debug/php-7.4.20/Zend/zend_gc.c:592
#5 0x0000558ab8215547 in gc_possible_root (ref=) at /usr/src/debug/php-7.4.20/Zend/zend_gc.c:642
#6 0x0000558ab8267376 in zend_assign_to_variable (strict=, value_type=8 '\b', value=0x7fd1aa144148, variable_ptr=)
at /usr/src/debug/php-7.4.20/Zend/zend_execute.h:135
#7 ZEND_FE_FETCH_R_SPEC_VAR_HANDLER () at /usr/src/debug/php-7.4.20/Zend/zend_vm_execute.h:21635
#8 0x0000558ab826fecf in execute_ex () at /usr/src/debug/php-7.4.20/Zend/zend_vm_execute.h:55971
#9 0x0000558ab8277b51 in zend_execute (op_array=0x7fd1b52802a0, return_value=) at /usr/src/debug/php-7.4.20/Zend/zend_vm_execute.h:57993
#10 0x0000558ab81f09b3 in zend_execute_scripts () at /usr/src/debug/php-7.4.20/Zend/zend.c:1679
#11 0x0000558ab818f180 in php_execute_script () at /usr/src/debug/php-7.4.20/main/main.c:2634
#12 0x0000558ab8279cd4 in do_cli (argc=2, argv=0x558ab98d5bf0) at /usr/src/debug/php-7.4.20/sapi/cli/php_cli.c:964
#13 0x0000558ab7ff57db in main (argc=2, argv=0x558ab98d5bf0) at /usr/src/debug/php-7.4.20/sapi/cli/php_cli.c:1359`

                                         辛苦 laruence!!
@laruence
Copy link
Owner

你的config.ini文件内容是啥

@bobitluo
Copy link
Author

我这个是为了验证问题使用 yaf/tools/cg/yaf_cg 创建的全新项目,没有 config.ini 文件

conf/application.ini 的内容:

[common]
application.directory = APPLICATION_PATH  "/application"
application.dispatcher.catchException = TRUE

[product : common]

@laruence
Copy link
Owner

噢,我知道了,这个是PHP7以后的已知问题,跟Yaf无关,你可以尝试去掉yaf的相关代码,用valgrind跑跑,一样有问题。

尽量避免对单一数组大量 $a[] = xxx这种形式吧。

@bobitluo
Copy link
Author

噢,我知道了,这个是PHP7以后的已知问题,跟Yaf无关,你可以尝试去掉yaf的相关代码,用valgrind跑跑,一样有问题。

尽量避免对单一数组大量 $a[] = xxx这种形式吧。

但是去掉yaf的相关代码或者在PHP7.3.28中却没有报segmentfault :(

@bobitluo
Copy link
Author

噢,我知道了,这个是PHP7以后的已知问题,跟Yaf无关,你可以尝试去掉yaf的相关代码,用valgrind跑跑,一样有问题。
尽量避免对单一数组大量 $a[] = xxx这种形式吧。

但是去掉yaf的相关代码或者在PHP7.3.28中却没有报segmentfault :(

而且改成 $data[$i] = [$i]; 问题依旧

@laruence
Copy link
Owner

噢, 我知道了,搞混了,问题修复了, 是 7.4以后get_gc不能为NULL了,之前没注意到。 回头发新版!

@bobitluo
Copy link
Author

感谢 laruence,又可以开心的升级版本了,😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants