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 segmentation fault with references #94

Closed
redcapital opened this issue Jul 20, 2016 · 7 comments
Closed

PHP7 segmentation fault with references #94

redcapital opened this issue Jul 20, 2016 · 7 comments

Comments

@redcapital
Copy link

Segfault when using PHP references. This is the test case which I tried to reduce as much as possible:

$ cat reftest.php
<?
$bad = unserialize('a:4:{i:1;a:1:{s:10:"verylongid";s:1:"1";}i:10;a:1:{s:10:"verylongid";s:2:"10";}i:16;a:1:{s:10:"verylongid";s:2:"16";}i:0;a:1:{s:8:"children";a:3:{i:16;R:6;i:10;R:4;i:1;R:2;}}}');
$p = msgpack_pack($bad);
$unpacked = msgpack_unpack($p);

$ php reftest.php
Segmentation fault
$ php --version
PHP 7.0.7-5~wheezy (cli) ( NTS )

Works in PHP 5.4 and possibly in any other PHP 5

@Sean-Der
Copy link
Member

Hey @redcapital

This is AWESOME I had some other people submit a bug that is probably the same, but couldn't get to the bottom of it because the cases were large (I couldn't get them smaller and reproduce either)

I will look at this tonight after work. thanks

@mente
Copy link

mente commented Oct 13, 2016

@Sean-Der have you forgot about it?

@NanneHuiges
Copy link

Here is some extra test data. I pulled it out of the unserialize for some clarity:

$bad2 = array (
	1 =>
		array (
			'a' => 'x',
		),
	30 =>
		array (
			'b' => 'y',
		),
	2 =>
		array (
			'c' => 'z',
		),
);

$bad2[0]['children'][2] = &$bad2[1];
$p = msgpack_pack($bad2);
$unpacked = msgpack_unpack($p);

this wil segfault in php7, but not in php5.5:

PHP 5.5.9-1ubuntu4.20 (cli) (built: Oct 3 2016 13:00:37)

works

PHP 7.0.12-1+deb.sury.org~xenial+1 (cli) ( NTS )

segmentation fault

Strange thing is, there are a lot of ways to have it not-segfault, for instance:

$bad2 = array (
	1 =>
		array (
			'a' => 'x',
		),
	2 =>
		array (
			'b' => 'y',
		),
	30 =>
		array (
			'c' => 'z',
		),
);

$bad2[0]['children'][2] = &$bad2[1];
$p = msgpack_pack($bad2);
$unpacked = msgpack_unpack($p);

This works in all versions.

mheijkoop pushed a commit to mheijkoop/msgpack-php that referenced this issue Dec 2, 2016
mheijkoop pushed a commit to mheijkoop/msgpack-php that referenced this issue Dec 2, 2016
workaround for msgpack#94, possibly at the expense of leaking a bit of memory?
Sean-Der pushed a commit that referenced this issue Dec 7, 2016
workaround for #94, possibly at the expense of leaking a bit of memory?
@Sean-Der
Copy link
Member

Sean-Der commented Dec 7, 2016

Hey @redcapital @mente @NanneHuiges sorry this got dropped, I don't work on PHP daily so hard to find time.

The good news is that @sodabrew contributed a patch that fixes this! Would you mind trying master? The example data in the first comment doesn't cause a segfault anymore.

@Sean-Der Sean-Der closed this as completed Dec 7, 2016
@NanneHuiges
Copy link

cool!
Do you mean the commit by @mheijkoop above?
Because I know for sure that it fixes my issue as she made it specifically for the same core-problem we had! :D

We're currently running our own compiled version with that patch ( e932088 ) and it is performing very well for us.

@Sean-Der
Copy link
Member

Sean-Der commented Dec 7, 2016

Yep! My mistake it was @mheijkoop who fixed it, I was trying to close tickets quickly last night and just grabbing anything that worked out of my clipring

@NanneHuiges
Copy link

👍 then this is considered fixed for us

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

4 participants