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

open file got segmentation fault when program reach file open limitation #4028

Closed
Appla opened this issue Jan 26, 2021 · 0 comments
Closed
Labels

Comments

@Appla
Copy link
Contributor

Appla commented Jan 26, 2021

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.
    when program reach the file open limit and doing any file open operation will trigger segmentation fault.
#0  0x00007f497e721865 in stream_opener (wrapper=<optimized out>, path=<optimized out>, mode=0x5579b68ebbab "rb", options=<optimized out>, opened_path=<optimized out>, context=<optimized out>) at ./thirdparty/php/streams/plain_wrapper.c:894
#1  0x00005579b6794d8a in _php_stream_open_wrapper_ex () at /usr/src/debug/php-7.4.14/main/streams/streams.c:2130
#2  0x00005579b6779e9e in php_stream_open_for_zend_ex (filename=0x7f49741194c8 "/kuaibao/www/kdhelp/artisan/logger/logger.php", handle=0x557a01751de0, mode=<optimized out>) at /usr/src/debug/php-7.4.14/main/main.c:1588
#3  0x00007f4990e45d55 in persistent_compile_file (type=8, file_handle=0x557a01751de0) at /usr/src/debug/php-7.4.14/ext/opcache/ZendAccelerator.c:1984
#4  persistent_compile_file (file_handle=0x557a01751de0, type=8) at /usr/src/debug/php-7.4.14/ext/opcache/ZendAccelerator.c:1914
#5  0x00005579b67a4112 in compile_filename (type=type@entry=8, filename=filename@entry=0x7f4951c2f070) at /usr/src/debug/php-7.4.14/Zend/zend_language_scanner.c:671
#6  0x00005579b6827975 in zend_include_or_eval (inc_filename=0x7f4951c2f070, type=8) at /usr/src/debug/php-7.4.14/Zend/zend_execute.c:4298
#7  0x00005579b68443da in ZEND_INCLUDE_OR_EVAL_SPEC_CV_HANDLER () at /usr/src/debug/php-7.4.14/Zend/zend_vm_execute.h:37773
#8  0x00005579b685bbaf in execute_ex () at /usr/src/debug/php-7.4.14/Zend/zend_vm_execute.h:57005
#9  0x00005579b67ce7a6 in zend_call_function () at /usr/src/debug/php-7.4.14/Zend/zend_execute_API.c:820
#10 0x00005579b66d702c in zif_spl_autoload_call () at /usr/src/debug/php-7.4.14/ext/spl/php_spl.c:452
#11 0x00005579b67ce682 in zend_call_function () at /usr/src/debug/php-7.4.14/Zend/zend_execute_API.c:833
#12 0x00005579b67cec7d in zend_lookup_class_ex (name=name@entry=0x7f499770aae0, key=0x7f499770aae0, flags=flags@entry=512) at /usr/src/debug/php-7.4.14/Zend/zend_execute_API.c:1002
#13 0x00005579b67cf4fc in zend_fetch_class_by_name () at /usr/src/debug/php-7.4.14/Zend/zend_execute_API.c:1433

looks like the the following function needs some check after file open operation

ext/swoole-src/thirdparty/php/streams/plain_wrapper.c:894
static php_stream *stream_opener(php_stream_wrapper *wrapper,
                                 const char *path,
                                 const char *mode,
                                 int options,
                                 zend_string **opened_path,
                                 php_stream_context *context STREAMS_DC) {
    if (((options & STREAM_DISABLE_OPEN_BASEDIR) == 0) && php_check_open_basedir(path)) {
        return NULL;
    }

    php_stream *stream;
    /** phar_open_archive_fp, cannot use async-io */
    if (EG(current_execute_data) && EG(current_execute_data)->func &&
        ZEND_USER_CODE(EG(current_execute_data)->func->type)) {
        const zend_op *opline = EG(current_execute_data)->opline;
        if (opline && opline->opcode == ZEND_INCLUDE_OR_EVAL &&
            (opline->extended_value & (ZEND_INCLUDE | ZEND_INCLUDE_ONCE | ZEND_REQUIRE | ZEND_REQUIRE_ONCE))) {
            size_t path_len = strlen(path);
            size_t phar_len = sizeof(".phar") - 1;
            if (path_len > phar_len && memcmp(path + path_len - phar_len, ".phar", phar_len) == 0) {
                goto _open_for_include;
            }
        }
    }
    /** include file, cannot use async-io */
    if (options & STREAM_OPEN_FOR_INCLUDE) {
    _open_for_include:
//  this call might return NULL
        stream = php_stream_fopen_rel(path, mode, opened_path, options);
        stream->ops = php_swoole_get_ori_php_stream_stdio_ops();
        return stream;
    }

    return stream_fopen_rel(path, mode, opened_path, options STREAMS_REL_CC);
}
  1. What did you expect to see?
    throws the error

  2. What did you see instead?
    Segmentation fault.

  3. What version of Swoole are you using (show your php --ri swoole)?

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.6.2
Built => Jan 26 2021 09:36:52
coroutine => enabled with boost asm context
debug => enabled
trace_log => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
PHP 7.4.14 (cli) (built: Jan  5 2021 10:45:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.14, Copyright (c), by Zend Technologies
    with Yasd v0.3.5, Our Copyright, by codinghuang

centos 7.9.2009 3.10.0-1160.6.1.el7.x86_64

gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
@Appla Appla changed the title file operation got segmentation fault when session reach file open limitation open file got segmentation fault when program reach file open limitation Jan 26, 2021
@matyhtf matyhtf added the fixed label Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants