Skip to content

Commit 2fb12be

Browse files
committed
Fixed bug #80411
References to null-serializations are stored as null, and as such are part of the reference count. Reminds me that we really need to deprecate the mess that is Serializable.
1 parent 233f507 commit 2fb12be

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ PHP NEWS
1818

1919
- Standard:
2020
. Fixed bug #80366 (Return Value of zend_fstat() not Checked). (sagpant, cmb)
21+
. Fixed bug #80411 (References to null-serialized object break serialize()).
22+
(Nikita)
2123

2224
- Tidy:
2325
. Fixed bug #77594 (ob_tidyhandler is never reset). (cmb)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #80411: References to null-serialized object break serialize()
3+
--FILE--
4+
<?php
5+
6+
class UnSerializable implements Serializable
7+
{
8+
public function serialize() {}
9+
public function unserialize($serialized) {}
10+
}
11+
12+
$unser = new UnSerializable();
13+
$arr = [$unser];
14+
$arr[1] = &$arr[0];
15+
$arr[2] = 'endcap';
16+
$arr[3] = &$arr[2];
17+
18+
$data = serialize($arr);
19+
echo $data . PHP_EOL;
20+
$recovered = unserialize($data);
21+
var_export($recovered);
22+
23+
?>
24+
--EXPECT--
25+
a:4:{i:0;N;i:1;N;i:2;s:6:"endcap";i:3;R:4;}
26+
array (
27+
0 => NULL,
28+
1 => NULL,
29+
2 => 'endcap',
30+
3 => 'endcap',
31+
)

ext/standard/var.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ static inline zend_long php_add_var_hash(php_serialize_data_t data, zval *var) /
677677

678678
if (zv) {
679679
/* References are only counted once, undo the data->n increment above */
680-
if (is_ref) {
680+
if (is_ref && Z_LVAL_P(zv) != -1) {
681681
data->n -= 1;
682682
}
683683

0 commit comments

Comments
 (0)