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

[BUG] Conflict of C code #14426

Closed
TimurFlush opened this issue Sep 28, 2019 · 33 comments
Closed

[BUG] Conflict of C code #14426

TimurFlush opened this issue Sep 28, 2019 · 33 comments

Comments

@TimurFlush
Copy link

TimurFlush commented Sep 28, 2019

Hello.

I get a segmentation fault in my application, but i don't understand why:

[28-Sep-2019 18:55:37] WARNING: [pool test] child 69480 exited on signal 11 (SIGSEGV - core dumped) after 386.591562 seconds from start

So, I know that fault is happening in Phalcon\View or Phalcon\View\Volt, but I don't know exactly where =(
In xdebug trace i don't found nothing useful

Who can give me advice?

P.S. My phalcon version is 4.0.0-rc.1, php is 7.3.9, mac os.

@TimurFlush
Copy link
Author

TimurFlush commented Sep 28, 2019

After restarting php-fpm, my application successfully handle one request and show me rendered template, but second request is segmentation fault.
If I delete the line responsible for template rendering, the script successfully runs and no errors occur.
XDebug trace give me understand that application running is stop when i'm register View service and call the render method.

@sergeyklay
Copy link
Contributor

Please follow this guide to understand how to generate the backtrace:

Did you build Phalcon from the source code? Could you please provide:

  • Commit SHA1 (if compiled from source)
  • Output of the php-config
  • Output of the php -v
  • Enabled modules
  • Web server name / version
  • Xdebug version
  • The way you install Phalcon

Would be useful to see views leads to segfault.

If I delete the line responsible for template rendering, the script successfully runs and no errors occur.

We need this line too.

@sergeyklay sergeyklay added Need information need script to reproduce Script is required to reproduce the issue labels Sep 28, 2019
@TimurFlush
Copy link
Author

Thank you, Sergey.
I'll answer as soon as i can.

@ruudboon
Copy link
Member

@TimurFlush If you need some assistance feel free to ping me at Discord.

@TimurFlush
Copy link
Author

TimurFlush commented Sep 28, 2019

@ruudboon Thank you, but i can't speak english. Only write)

@TimurFlush
Copy link
Author

TimurFlush commented Sep 28, 2019

@sergeyklay
Commit SHA1 (if compiled from source):

commit a48b31967a1ce27c10cbed61bee42e0c90addc86 (HEAD, tag: v4.0.0-rc.1)
Merge: da5eb91e8 41d398bbf
Author: Serghei Iakovlev <sergeyklay@users.noreply.github.com>
Date:   Mon Sep 23 08:15:04 2019 +0300

    Merge pull request #14405 from phalcon/4.0.x
    
    4.0.0-rc.1

Output of the phpize:

PHP Api Version:         20180731
Zend Module Api No:      20180731
Zend Extension Api No:   320180731

Output of the php-config:

Usage: /Users/flush/Desktop/php73/bin/php-config [OPTION]
Options:
  --prefix            [/Users/flush/Desktop/php73]
  --includes          [-I/Users/flush/Desktop/php73/include/php -I/Users/flush/Desktop/php73/include/php/main -I/Users/flush/Desktop/php73/include/php/TSRM -I/Users/flush/Desktop/php73/include/php/Zend -I/Users/flush/Desktop/php73/include/php/ext -I/Users/flush/Desktop/php73/include/php/ext/date/lib]
  --ldflags           [ -L/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib]
  --libs              [  -lresolv -lm  -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm ]
  --extension-dir     [/Users/flush/Desktop/php73/lib/php/extensions/no-debug-non-zts-20180731]
  --include-dir       [/Users/flush/Desktop/php73/include/php]
  --man-dir           [/Users/flush/Desktop/php73/php/man]
  --php-binary        [/Users/flush/Desktop/php73/bin/php]
  --php-sapis         [ cli fpm phpdbg cgi]
  --configure-options [--prefix=/Users/flush/Desktop/php73 --enable-fpm --without-iconv]
  --version           [7.3.9]
  --vernum            [70309]

Output of the php -v:

PHP 7.3.9 (cli) (built: Sep 19 2019 09:47:44) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.9, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.9, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.7.2, Copyright (c) 2002-2019, by Derick Rethans

Enabled modules:

bcmath, Core, ctype, curl, date, dom, fileinfo, filter
gd, gmp, hash, intl, json ,libxml, mbstring, openssl, pcntl, pcre, PDO, pdo_pgsql, pdo_sqlite, phalcon, Phar, posix, psr, redis, Reflection, session, SimpleXML, sockets, sodium, SPL, sqlite3, standard, tokenizer, xdebug, xml, xmlreader, xmlwriter, Zend OPcache, zip, XDebug

Web server name / version: nginx version: nginx/1.17.3
Xdebug version:

xdebug support => enabled
Version => 2.7.2

The way you install Phalcon:

git checkout tags/v4.0.0-rc.1 && cd build && ./install

Core dump: https://imgur.com/a/jbxzEEE
OS: Mac OS Mojave 10.14.5

@TimurFlush
Copy link
Author

@sergeyklay Can I tell with you in Discord?

@sergeyklay
Copy link
Contributor

Yes, just ping me there

@TimurFlush
Copy link
Author

Trace:

MBP-Flush:Desktop flush$ lldb --core "/Users/flush/Desktop/segfault.76482"
(lldb) target create --core "/Users/flush/Desktop/segfault.76482"
Core file '/Users/flush/Desktop/segfault.76482' (x86_64) was loaded.
(lldb) bt all
php-fpm was compiled with optimization - stepping may behave oddly; variables may not be available.
* thread #1, stop reason = signal SIGSTOP
  * frame #0: 0x0000000101b09b11 php-fpm`zend_hash_find [inlined] zend_hash_find_bucket(ht=0x0000000102669658, key=0x0000000105c79fb0, known_hash='\0') at zend_hash.c:580:6 [opt]
    frame #1: 0x0000000101b09ae1 php-fpm`zend_hash_find(ht=0x0000000102669658, key=0x0000000105c79fb0) at zend_hash.c:2092 [opt]
    frame #2: 0x0000000101b85df5 php-fpm`ZEND_ISSET_ISEMPTY_DIM_OBJ_SPEC_TMPVAR_CV_HANDLER [inlined] zend_hash_find_ex(ht=<unavailable>, key=<unavailable>, known_hash='\0') at zend_hash.h:179:10 [opt]
    frame #3: 0x0000000101b85dea php-fpm`ZEND_ISSET_ISEMPTY_DIM_OBJ_SPEC_TMPVAR_CV_HANDLER [inlined] zend_hash_find_ex_ind(ht=<unavailable>, key=<unavailable>, known_hash='\0') at zend_hash.h:352 [opt]
    frame #4: 0x0000000101b85dea php-fpm`ZEND_ISSET_ISEMPTY_DIM_OBJ_SPEC_TMPVAR_CV_HANDLER(execute_data=0x0000000102623ad0) at zend_vm_execute.h:17535 [opt]
    frame #5: 0x0000000101b3d1f8 php-fpm`execute_ex(ex=0x0000000102623ad0) at zend_vm_execute.h:55334:7 [opt]
    frame #6: 0x0000000101ae604f php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:756:3 [opt]
    frame #7: 0x00000001050f963d phalcon.so`zephir_call_user_func_array + 205
    frame #8: 0x000000010548125e phalcon.so`zim_Phalcon_Di_Service_resolve + 2574
    frame #9: 0x0000000101ae60b9 php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:770:4 [opt]
    frame #10: 0x00000001050b7645 phalcon.so`zephir_call_user_function + 2117
    frame #11: 0x00000001050b6aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #12: 0x00000001050eccbf phalcon.so`zim_Phalcon_Di_get + 2639
    frame #13: 0x0000000101b70d43 php-fpm`ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER(execute_data=0x0000000102623760) at zend_vm_execute.h:1102:4 [opt]
    frame #14: 0x0000000101b3d1f8 php-fpm`execute_ex(ex=0x0000000102623680) at zend_vm_execute.h:55334:7 [opt]
    frame #15: 0x0000000101ae604f php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:756:3 [opt]
    frame #16: 0x0000000105481339 phalcon.so`zim_Phalcon_Di_Service_resolve + 2793
    frame #17: 0x0000000101ae60b9 php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:770:4 [opt]
    frame #18: 0x00000001050b7645 phalcon.so`zephir_call_user_function + 2117
    frame #19: 0x00000001050b6aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #20: 0x00000001050eccbf phalcon.so`zim_Phalcon_Di_get + 2639
    frame #21: 0x0000000101ae60b9 php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:770:4 [opt]
    frame #22: 0x00000001050b7645 phalcon.so`zephir_call_user_function + 2117
    frame #23: 0x00000001050b6aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #24: 0x00000001050ee722 phalcon.so`zim_Phalcon_Di_getShared + 690
    frame #25: 0x0000000101ae60b9 php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:770:4 [opt]
    frame #26: 0x00000001050b7645 phalcon.so`zephir_call_user_function + 2117
    frame #27: 0x00000001050b6aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #28: 0x000000010547f79c phalcon.so`zim_Phalcon_Di_Injectable___get + 1724
    frame #29: 0x0000000101ae60b9 php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:770:4 [opt]
    frame #30: 0x0000000101b3308e php-fpm`zend_std_read_property [inlined] zend_std_call_getter(zobj=<unavailable>, prop_name=<unavailable>, retval=<unavailable>) at zend_object_handlers.c:211:2 [opt]
    frame #31: 0x0000000101b32fef php-fpm`zend_std_read_property(object=<unavailable>, member=<unavailable>, type=<unavailable>, cache_slot=<unavailable>, rv=<unavailable>) at zend_object_handlers.c:711 [opt]
    frame #32: 0x0000000101b79e3f php-fpm`ZEND_FETCH_OBJ_R_SPEC_UNUSED_CONST_HANDLER(execute_data=0x00000001026233c0) at zend_vm_execute.h:30996:13 [opt]
    frame #33: 0x0000000101b3d1f8 php-fpm`execute_ex(ex=0x00000001026233c0) at zend_vm_execute.h:55334:7 [opt]
    frame #34: 0x0000000101ae604f php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:756:3 [opt]
    frame #35: 0x00000001050f963d phalcon.so`zephir_call_user_func_array + 205
    frame #36: 0x0000000105230ced phalcon.so`zim_Phalcon_Mvc_Micro_LazyLoader_callMethod + 1917
    frame #37: 0x0000000101ae60b9 php-fpm`zend_call_function(fci=<unavailable>, fci_cache=<unavailable>) at zend_execute_API.c:770:4 [opt]
    frame #38: 0x00000001050b7645 phalcon.so`zephir_call_user_function + 2117
    frame #39: 0x00000001050b6aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #40: 0x0000000105198ed3 phalcon.so`zim_Phalcon_Mvc_Micro_handle + 20611
    frame #41: 0x0000000101b708f1 php-fpm`ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER(execute_data=0x00000001026231e0) at zend_vm_execute.h:980:4 [opt]
    frame #42: 0x0000000101b3d1f8 php-fpm`execute_ex(ex=0x0000000102623130) at zend_vm_execute.h:55334:7 [opt]
    frame #43: 0x0000000101b3d3b5 php-fpm`zend_execute(op_array=0x0000000102676000, return_value=0x0000000000000000) at zend_vm_execute.h:60881:2 [opt]
    frame #44: 0x0000000101af5fb5 php-fpm`zend_execute_scripts(type=8, retval=0x0000000000000000, file_count=3) at zend.c:1568:4 [opt]
    frame #45: 0x0000000101a8cd2d php-fpm`php_execute_script(primary_file=<unavailable>) at main.c:2639:14 [opt]
    frame #46: 0x0000000101bc0ece php-fpm`main(argc=<unavailable>, argv=<unavailable>) at fpm_main.c:1950:4 [opt]
    frame #47: 0x00007fff7f8bc3d5 libdyld.dylib`start + 1
    frame #48: 0x00007fff7f8bc3d5 libdyld.dylib`start + 1
(lldb) 

@sergeyklay sergeyklay removed the need script to reproduce Script is required to reproduce the issue label Sep 29, 2019
@TimurFlush
Copy link
Author

Without optimization on the php-fpm compiling

MBP-Flush:Desktop flush$ lldb --core core.74773
(lldb) target create --core "core.74773"
Core file '/Users/flush/Desktop/core.74773' (x86_64) was loaded.
(lldb) bt all
* thread #1, stop reason = signal SIGSTOP
  * frame #0: 0x000000010f1f344a php-fpm`zend_hash_find [inlined] zend_hash_find_bucket(ht=0x000000010fe65690, key=0x0000000113c9db70, known_hash='\0') at zend_hash.c:580:6
    frame #1: 0x000000010f1f3387 php-fpm`zend_hash_find(ht=0x000000010fe65690, key=0x0000000113c9db70) at zend_hash.c:2092
    frame #2: 0x000000010f2fdb45 php-fpm`ZEND_ISSET_ISEMPTY_DIM_OBJ_SPEC_TMPVAR_CV_HANDLER [inlined] zend_hash_find_ex(ht=0x000000010fe65690, key=0x0000000113c9db70, known_hash='\0') at zend_hash.h:179:10
    frame #3: 0x000000010f2fdb18 php-fpm`ZEND_ISSET_ISEMPTY_DIM_OBJ_SPEC_TMPVAR_CV_HANDLER [inlined] zend_hash_find_ex_ind(ht=0x000000010fe65690, key=0x0000000113c9db70, known_hash='\0') at zend_hash.h:352
    frame #4: 0x000000010f2fdaf9 php-fpm`ZEND_ISSET_ISEMPTY_DIM_OBJ_SPEC_TMPVAR_CV_HANDLER(execute_data=0x000000010fe22ad0) at zend_vm_execute.h:17535
    frame #5: 0x000000010f26dbb4 php-fpm`execute_ex(ex=0x000000010fe22840) at zend_vm_execute.h:55334:7
    frame #6: 0x000000010f199911 php-fpm`zend_call_function(fci=0x00007ffee10c4060, fci_cache=0x00007ffee10c4040) at zend_execute_API.c:756:3
    frame #7: 0x0000000110f1463d phalcon.so`zephir_call_user_func_array + 205
    frame #8: 0x000000011129c25e phalcon.so`zim_Phalcon_Di_Service_resolve + 2574
    frame #9: 0x000000010f199a0e php-fpm`zend_call_function(fci=0x00007ffee10c46a8, fci_cache=0x00007ffee10c4708) at zend_execute_API.c:770:4
    frame #10: 0x0000000110ed2645 phalcon.so`zephir_call_user_function + 2117
    frame #11: 0x0000000110ed1aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #12: 0x0000000110f07cbf phalcon.so`zim_Phalcon_Di_get + 2639
    frame #13: 0x000000010f2b1a65 php-fpm`ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER(execute_data=0x000000010fe22680) at zend_vm_execute.h:1102:4
    frame #14: 0x000000010f26dbb4 php-fpm`execute_ex(ex=0x000000010fe22680) at zend_vm_execute.h:55334:7
    frame #15: 0x000000010f199911 php-fpm`zend_call_function(fci=0x00007ffee10c5190, fci_cache=0x00007ffee10c5170) at zend_execute_API.c:756:3
    frame #16: 0x000000011129c339 phalcon.so`zim_Phalcon_Di_Service_resolve + 2793
    frame #17: 0x000000010f199a0e php-fpm`zend_call_function(fci=0x00007ffee10c5668, fci_cache=0x00007ffee10c56c8) at zend_execute_API.c:770:4
    frame #18: 0x0000000110ed2645 phalcon.so`zephir_call_user_function + 2117
    frame #19: 0x0000000110ed1aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #20: 0x0000000110f07cbf phalcon.so`zim_Phalcon_Di_get + 2639
    frame #21: 0x000000010f199a0e php-fpm`zend_call_function(fci=0x00007ffee10c5f28, fci_cache=0x00007ffee10c5f88) at zend_execute_API.c:770:4
    frame #22: 0x0000000110ed2645 phalcon.so`zephir_call_user_function + 2117
    frame #23: 0x0000000110ed1aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #24: 0x0000000110f09722 phalcon.so`zim_Phalcon_Di_getShared + 690
    frame #25: 0x000000010f199a0e php-fpm`zend_call_function(fci=0x00007ffee10c66b8, fci_cache=0x00007ffee10c6718) at zend_execute_API.c:770:4
    frame #26: 0x0000000110ed2645 phalcon.so`zephir_call_user_function + 2117
    frame #27: 0x0000000110ed1aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #28: 0x000000011129a79c phalcon.so`zim_Phalcon_Di_Injectable___get + 1724
    frame #29: 0x000000010f199a0e php-fpm`zend_call_function(fci=0x00007ffee10c6ef8, fci_cache=0x00007ffee10c6ed8) at zend_execute_API.c:770:4
    frame #30: 0x000000010f252f54 php-fpm`zend_std_call_getter(zobj=0x000000010fe66480, prop_name=0x0000000113c28cb0, retval=0x000000010fe22450) at zend_object_handlers.c:211:2
    frame #31: 0x000000010f2529f3 php-fpm`zend_std_read_property(object=0x000000010fe223e0, member=0x000000011445caf0, type=0, cache_slot=0x000000010fefe8d0, rv=0x000000010fe22450) at zend_object_handlers.c:711:4
    frame #32: 0x000000010f2d287a php-fpm`ZEND_FETCH_OBJ_R_SPEC_UNUSED_CONST_HANDLER(execute_data=0x000000010fe223c0) at zend_vm_execute.h:30996:13
    frame #33: 0x000000010f26dbb4 php-fpm`execute_ex(ex=0x000000010fe222c0) at zend_vm_execute.h:55334:7
    frame #34: 0x000000010f199911 php-fpm`zend_call_function(fci=0x00007ffee10c7860, fci_cache=0x00007ffee10c7840) at zend_execute_API.c:756:3
    frame #35: 0x0000000110f1463d phalcon.so`zephir_call_user_func_array + 205
    frame #36: 0x000000011104bced phalcon.so`zim_Phalcon_Mvc_Micro_LazyLoader_callMethod + 1917
    frame #37: 0x000000010f199a0e php-fpm`zend_call_function(fci=0x00007ffee10c7e68, fci_cache=0x00007ffee10c7ec8) at zend_execute_API.c:770:4
    frame #38: 0x0000000110ed2645 phalcon.so`zephir_call_user_function + 2117
    frame #39: 0x0000000110ed1aeb phalcon.so`zephir_call_class_method_aparams + 187
    frame #40: 0x0000000110fb3ed3 phalcon.so`zim_Phalcon_Mvc_Micro_handle + 20611
    frame #41: 0x000000010f2b0dc2 php-fpm`ZEND_DO_FCALL_SPEC_RETVAL_UNUSED_HANDLER(execute_data=0x000000010fe22130) at zend_vm_execute.h:980:4
    frame #42: 0x000000010f26dbb4 php-fpm`execute_ex(ex=0x000000010fe22030) at zend_vm_execute.h:55334:7
    frame #43: 0x000000010f26e1e3 php-fpm`zend_execute(op_array=0x000000010fe74000, return_value=0x0000000000000000) at zend_vm_execute.h:60881:2
    frame #44: 0x000000010f1c0fa2 php-fpm`zend_execute_scripts(type=8, retval=0x0000000000000000, file_count=3) at zend.c:1568:4
    frame #45: 0x000000010f0e61af php-fpm`php_execute_script(primary_file=0x00007ffee10c96e0) at main.c:2639:14
    frame #46: 0x000000010f3c2357 php-fpm`main(argc=5, argv=0x00007ffee10c9a20) at fpm_main.c:1950:4
    frame #47: 0x00007fff7f8bc3d5 libdyld.dylib`start + 1

@TimurFlush
Copy link
Author

TimurFlush commented Sep 29, 2019

I'm very close.

If i pass the third argument as $_POST:

$req = (new \Phalcon\Http\Messages\ServerRequestFactory())->load($_SERVER, $_GET, $_POST);

will be the segfault in time during a call to an unknown problematic method from \Phalcon\Http\Messages\ServerRequest

Without $_POST, the segfault is not occur,
But the trick is that $_POST is empty ($_POST === [] === true) and my request is a GET request
If i just pass an empty array instead of $_POST then the segfault is not occur 0_o

P.S. the ServerRequest pass to https://github.com/thephpleague/oauth2-server/blob/master/src/Grant/AuthCodeGrant.php#L242
P.P.S. Method of the request is GET. Parameters: client_id=uuid&response_type=code

@TimurFlush
Copy link
Author

@niden Please check

@TimurFlush
Copy link
Author

TimurFlush commented Sep 29, 2019

Sure, I can rewrite the ServerRequestFactory and ServerRequest classes and try to find the problem, but all important methods in ServerRequestFactory is private(
@niden, Sergey told me that you author this classes, therefore i tag you.

P.S: I can try to unlock private methods in the Factory class via Reflection and rewrite him, but it very long(
P.P.S: Until all that I can to propose it's my application for reproduce

@TimurFlush
Copy link
Author

TimurFlush commented Sep 29, 2019

I rewrite the ServerRequestFactory class, result of rewriting you can see by link https://imgur.com/a/N4M8ONe
And i not see segmentation fault

I quote @sergeyklay, him told that There are some problems with super global arrays in Zephir, so the $_SERVER php variable differs from the _SERVER zephir variable

In the end, instead of the checkNullArray method returning an array, it returns undefined and occur the Segmentation Fault.

I support him.
Therefore, we need to cast the undefined to array before returning in the checkNullArray method OR make users specify super global variables directly from PHP in the Zephir methods

@TimurFlush TimurFlush changed the title Segmentation fault [BUG] Incorrect behavior of superglobals in ServerRequestFactory Sep 29, 2019
@niden
Copy link
Member

niden commented Sep 29, 2019

This has been resolved

@TimurFlush thank you for reporting this. Nice catch. The code is in the v4 branch so if you can please build from there and let us know if there are additional issues.

@niden niden closed this as completed Sep 29, 2019
@TimurFlush
Copy link
Author

TimurFlush commented Sep 29, 2019

@niden , i still have the segfault (
First I compiled Phalcon from build directory and i got the segfault.
After I compiled Phalcon via Zephir and i got the same result

@TimurFlush
Copy link
Author

Maybe Zephir just incorrectly extracts these super global variables?

@TimurFlush
Copy link
Author

TimurFlush commented Sep 29, 2019

If I pass the super global variables from php environment I don't get the segfault

@niden niden reopened this Sep 29, 2019
@niden
Copy link
Member

niden commented Sep 29, 2019

So to summarize:

$factory = new \Phalcon\Http\Messages\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET, $_POST);

No segfault

$factory = new \Phalcon\Http\Messages\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET);

Segfault ?

@niden
Copy link
Member

niden commented Sep 30, 2019

These are the tests I have added:

https://github.com/phalcon/cphalcon/blob/4.0.x/tests/unit/Http/Message/ServerRequestFactory/LoadCest.php#L452

I am wondering if your superglobals are already defined but are null or something (especially $_POST)

@TimurFlush
Copy link
Author

I got the segfault with the following code:

$factory = new \Phalcon\Http\Messages\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET, $_POST);

And i don't get segfault:

$factory = new \Phalcon\Http\Messages\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET);

OR

$factory = new \Phalcon\Http\Messages\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);

@TimurFlush
Copy link
Author

Until I don't understand the reason by this occur

@TimurFlush
Copy link
Author

TimurFlush commented Sep 30, 2019

@niden, this segfault occur when I pass $_SERVER, $_GET, $_POST to ServerRequestFactory::load() and render a VOLT template via anonimous function in View\Simple::registerEngines().
But If I register the VOLT engine as the following string: "Phalcon\Mvc\View\Engine\VOLT" then the segfault not occur.
And If i move problematic code in separate file the segfault will not ocurr.
In the end, this segfault ocurr only in my micro application with all the factors which I wrote above.
Confusion 😥

@TimurFlush
Copy link
Author

Yet another the interest behavior

If i will enable the OPCache extension then first request is successful, other requests give the segfault
If i will disable the OPCache extension then all request give the segfault

@TimurFlush TimurFlush changed the title [BUG] Incorrect behavior of superglobals in ServerRequestFactory [BUG] Conflict of C code Sep 30, 2019
@niden
Copy link
Member

niden commented Sep 30, 2019

@TimurFlush Do me a favor please.

You get the segfault by using this:

$factory = new \Phalcon\Http\Messages\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET, $_POST);

Can you var_dump $_SERVER, $_GET and $_POST and paste it here?

@ekmst
Copy link
Contributor

ekmst commented Sep 30, 2019

@niden I have all three examples give a fatal error:

Fatal error: Uncaught Phalcon\Http\Message\Exception\InvalidArgumentException: Unsupported protocol HTTP/1.1 in...
$factory = new \Phalcon\Http\Message\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET, $_POST);

$factory = new \Phalcon\Http\Message\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET);

$factory = new \Phalcon\Http\Message\ServerRequestFactory();
$req = $factory->load($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
PHP: 7.2.13
Phalcon:
Version => 4.0.0-rc.1
Build Date => Sep 30 2019 19:41:10
Powered by Zephir => Version 0.12.4-b386980

@niden
Copy link
Member

niden commented Sep 30, 2019

@ekmst This is not related to what @TimurFlush is experiencing. Your error comes from the calculation of the protocol when using the SERVER_PROTOCOL

I can see that it is HTTP/1.1. Now from your message

Unsupported protocol HTTP/1.1

there is a mishap with the logic in the code when we split the protocol to figure out its number. Since the code returns HTTP/1.1 vs 1.1 there is no match and therefore the error.

It is weird though because I wrote tests on that and they all passed. I will have a look at it again, maybe simplify the code a bit.

This is where the error comes from: https://github.com/phalcon/cphalcon/blob/4.0.x/phalcon/Http/Message/ServerRequestFactory.zep#L486

@niden
Copy link
Member

niden commented Sep 30, 2019

@ekmst I just pushed a rework of the protocol detection. Would you mind checking it, to see if your error still persists?

@ekmst
Copy link
Contributor

ekmst commented Sep 30, 2019

@ekmst I just pushed a rework of the protocol detection. Would you mind checking it, to see if your error still persists?

@niden helped. Thank you!

@TimurFlush
Copy link
Author

@niden
Creating components outside of closure fixes the issue
Please see https://imgur.com/a/6L1gwy6

@niden
Copy link
Member

niden commented Oct 1, 2019

@TimurFlush Thank you for this report.

If this fixes your problem then let's close this issue and open one for further investigation with the code that does produce the segfault. I know Zephir doesn't like method properties in closures so we need to work on that. Perhaps they are related.

In the new issue, if you can, can you please attach a sample script that we can work with?

@TimurFlush
Copy link
Author

@niden, Yes.

I think that we can close this issue, but a sample script only is my application which I will provide him you.

@ruudboon
Copy link
Member

ruudboon commented Oct 1, 2019

Further investigation will be done here zephir-lang/zephir#1934

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

5 participants