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

Segmentation fault for special syntax #219

Open
ziaratban opened this issue Sep 16, 2021 · 3 comments
Open

Segmentation fault for special syntax #219

ziaratban opened this issue Sep 16, 2021 · 3 comments
Assignees

Comments

@ziaratban
Copy link

Hi

a.php

<?php
require 'b.php'; // comment this line for fix
require 'c.php';

b.php

<?php
function t(){
    strpos('',''); // or comment this line for fix
}

c.php

$r = new \parallel\Runtime();
$r->run(static function(){
    require 'b.php';
    t();
});
root# php a.php
Sep 16 12:11:47 server1 kernel: php[1744]: segfault at 10 ip 0000000000000010 sp 000014a4d679ea78 error 14
Sep 16 12:11:47 server1 kernel: Code: Unable to access opcode bytes at RIP 0xffffffffffffffe6.
root# php -v
PHP 8.0.10 (cli) (built: Sep 16 2021 12:16:25) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v4.0.10, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.10, Copyright (c), by Zend Technologies
@ziaratban
Copy link
Author

ziaratban commented Sep 16, 2021

Other behavior :
edit c.php

$r = new \parallel\Runtime();
$r->run(static function(){
    substr('',''); // <--- added
    require 'b.php';
    t();
});

output :

Fatal error: Uncaught TypeError: substr(): Argument #2 ($offset) must be of type int, string given in /root/b.php:3
Stack trace:
#0 /root/b.php(3): substr('', '')
#1 /root/c.php(6): t()
#2 {main}
  thrown in /root/b.php on line 3

@ziaratban
Copy link
Author

ziaratban commented Sep 16, 2021

Fixed

edit b.php

$r = new \parallel\Runtime();
$r->run(static function(){
    opcache_invalidate('b.php'); // <--- added
    require 'b.php';
    t();
});

@realFlowControl
Copy link
Collaborator

Hey @ziaratban,

sorry for radio silence. First of all: thanks for this nice and easy reproducer!
I gave it a quick try and was able to reproduce this with OPcache, but not without OPcache.
I am pretty new to parallel, but I am not sure if require/include are actually supported, another way to fix this is to include b.php not using require/include, but using the bootstrap mechanism in b.php like this:

<?php
$r = new \parallel\Runtime('b.php');
$r->run(static function(){
    t();
});

This fixes it at leas for me on:

$ php -v
PHP 8.3.11-dev (cli) (built: Jul 23 2024 20:50:22) (ZTS)
Copyright (c) The PHP Group
Zend Engine v4.3.11-dev, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.11-dev, Copyright (c), by Zend Technologies

@realFlowControl realFlowControl self-assigned this Jul 23, 2024
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