[php-src] PR #25945: ext/session: Fix php_serialize session decoder keeping a top-level reference
| From: | jorgsowa | Date: | Mon, 30 Nov 2026 13:43:54 +0000 |
| Subject: | [php-src] PR #25945: ext/session: Fix php_serialize session decoder keeping a top-level reference | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-41254@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/25945
Author: jorgsowa
Session data like
a:1:{s:1:"b";R:1;} made $_SESSION a reference
to a reference, tripping a VM assertion on access. Unwrap it like unserialize().
Debug builds fail an assertion when $_SESSION is read:
```
Assertion failed: (zval_get_type(&(*(ret))) != 10), function _get_zval_ptr_tmp, file
zend_execute.c, line 255.
```
In release builds, $a = $_SESSION gives a reference instead of a copy, foreach
($_SESSION ...) fails with "foreach() argument must be of type array|object, array
given", writing $_SESSION['x'] throws "Cannot use a scalar value as an
array", and session_encode() reports a non-existent session.
PHP's own encoder never writes such data. It needs crafted session storage or crafted
session_decode() input.
unserialize() already handles this by unwrapping a top-level reference after
PHP_VAR_UNSERIALIZE_DESTROY:
https://github.com/php/php-src/blob/174df2785f81024d8c2ab6900b513c1f4f7de6c5/ext/standard/var.c#L1598-L1603
The session decoder now does the same, so $_SESSION gets the value unserialize() would
return.