-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
PHP 8.2 Segmentation fault on nesbot/carbon #11455
Comments
The problem was solved by importing the ext/date of the PHP-8.1 branch into the PHP-8.2 branch. Perhaps this is an ext/date issue. I will investigate further. |
Segmentation violation appears to have occurred after this commit: 85fbc6e |
I am trying to come up with the smallest code that will reproduce the problem, but it is difficult. |
memo: lldb backtrace
|
@zeriyoshi <?php
class MyDateTimeImmutable extends DateTimeImmutable {
public function __construct(
string $datetime = "now",
?DateTimeZone $timezone = null,
public ?stdClass $myProperty = null,
) {
parent::__construct($datetime, $timezone);
}
}
$datetime = new MyDateTimeImmutable('2022-12-22T11:26:00Z', myProperty: new stdClass);
$datetime->myProperty->field = str_repeat("hello", 3);
$serialized = serialize($datetime);
var_dump($datetime->myProperty);
$unserialized = unserialize($serialized);
var_dump($unserialized); This code causes a crash in malloc(). The fix is simple, it's a matter of adding the refcount if a new entry is added to the hash table. Executing my testcase now works. I tried this with your Carbon fork, and it no longer crashes in malloc(), but the test fails. This is because Carbon tries to serialize a Closure stored in So although my patch fixes the underlying bug in this issue, I'm not so sure Carbon can just get rid of their custom serialization. |
@nielsdos We have also identified an issue on the Carbon side that needs to be addressed by Carbon. As soon as this fix is incorporated into PHP 8.2-dev, I will suggest a fix to Carbon (though it may take some time, as I am not familiar with Carbon. A fix by the maintainer would be even better :) ). |
Indeed, on Carbon side, we use the custom serialization to dump/restore some other parameters, also we'll need to support the bugged versions for a while as it makes maintenance more difficult if few users are stuck on an old patch, but putting this out of the way for the next patch is already super useful. |
Great, thanks for checking. I opened a PR. |
@nielsdos |
@zeriyoshi |
@nielsdos Thank you! It was very easy to understand. I will use it as a reference! |
Description
There is a bug in
nesbot/carbon
that causes a segmentation violation when serialize / unserialize is executed in PHP 8.2 and later.In response to this bug,
nesbot/carbon
has a workaround that implements a userland serialization algorithm, which significantly worse performance. (briannesbitt/Carbon#2644)This can be reproduced by following these steps:
backtrace (gdb):
zbacktrace (gdb)
PHP Version
PHP 8.2.7
PHP 8.2.8-dev
PHP 8.3.0-dev
master
96ea06aOperating System
Debian 11.7
The text was updated successfully, but these errors were encountered: