Skip to content

Commit b2b7519

Browse files
author
Martin Hoch
committed
serialize: Fixed handling of nested object references
The removed if in var.c caused serialize to not handle object references correctly under certain circumstances. See tests/serialize/serialization_objects_019.phpt The bug was originally introduced in commit 6c5942f, and the problematic line was last modified in commit bb0b4eb. (Fixes oss-fuzz #44954) The testcase from bb0b4eb still passes.
1 parent 5cad1a7 commit b2b7519

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
Object serialization with references
3+
--FILE--
4+
<?php
5+
function gen() {
6+
$s = new stdClass;
7+
$r = new stdClass;
8+
$r->a = [$s];
9+
$r->b = $r->a;
10+
return $r;
11+
}
12+
var_dump(serialize(gen()));
13+
?>
14+
--EXPECTF--
15+
string(78) "O:8:"stdClass":2:{s:1:"a";a:1:{i:0;O:8:"stdClass":0:{}}s:1:"b";a:1:{i:0;r:3;}}"
16+
17+

ext/standard/var.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,6 @@ static inline zend_long php_add_var_hash(php_serialize_data_t data, zval *var) /
666666
/* pass */
667667
} else if (Z_TYPE_P(var) != IS_OBJECT) {
668668
return 0;
669-
} else if (Z_REFCOUNT_P(var) == 1 && (Z_OBJ_P(var)->properties == NULL || GC_REFCOUNT(Z_OBJ_P(var)->properties) == 1)) {
670-
return 0;
671669
}
672670

673671
/* References to objects are treated as if the reference didn't exist */

0 commit comments

Comments
 (0)