com php-src: Fixed bug #72229 (Wrong reference when serialize/unserialize an object): NEWS ext/standard/tests/serialize/bug72229.phpt
ext/standard/var.c

From: Date: Tue, 17 May 2016 09:40:26 +0000
Subject: com php-src: Fixed bug #72229 (Wrong reference when serialize/unserialize an object): NEWS ext/standard/tests/serialize/bug72229.phpt
ext/standard/var.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-92159@lists.php.net to get a copy of this message
Commit: 7989db975f325d83b461a46c3dc75a81fcc27795 Author: Xinchen Hui <laruence@gmail.com> Tue, 17 May 2016 17:40:26 +0800 Parents: 7e5ea3c305409fdda8f1f6e35a32a65a0394b72b Branches: PHP-7.0 Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7989db975f325d83b461a46c3dc75a81fcc27795 Log: Fixed bug #72229 (Wrong reference when serialize/unserialize an object) Bugs: https://bugs.php.net/72229 Changed paths: M NEWS A ext/standard/tests/serialize/bug72229.phpt M ext/standard/var.c Diff: diff --git a/NEWS b/NEWS index c75fe55..295f4a2 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,8 @@ PHP NEWS . Fixed bug #72197 (pg_lo_create arbitrary read). (Anatol) - Standard: + . Fixed bug #72229 (Wrong reference when serialize/unserialize an object). + (Laruence) . Fixed bug #72193 (dns_get_record returns array containing elements of type 'unknown'). (Laruence) . Fixed bug #72017 (range() with float step produces unexpected result). diff --git a/ext/standard/tests/serialize/bug72229.phpt b/ext/standard/tests/serialize/bug72229.phpt new file mode 100644 index 0000000..17c393c --- /dev/null +++ b/ext/standard/tests/serialize/bug72229.phpt @@ -0,0 +1,53 @@ +--TEST-- +Bug #72229 (Wrong reference when serialize/unserialize an object) +--FILE-- +<?php +class C1 +{ + public $arr1 = array(); + public $arr2 = array(); + public function __construct() + { + $this->arr1[0] = $this; + $this->arr2[0] = $this->arr1[0]; + $var1 = &$this->arr1[0]; // Set a reference... + unset($var1); // ... and unset it. + } +} +$Obj1 = new C1(); +$txt1 = serialize($Obj1); +$Obj2 = unserialize($txt1); +$Obj1->arr2[0] = 50; +print_r($Obj1); +$Obj2->arr2[0] = 50; +print_r($Obj2); +?> +--EXPECTF-- +C1 Object +( + [arr1] => Array + ( + [0] => C1 Object + *RECURSION* + ) + + [arr2] => Array + ( + [0] => 50 + ) + +) +C1 Object +( + [arr1] => Array + ( + [0] => C1 Object + *RECURSION* + ) + + [arr2] => Array + ( + [0] => 50 + ) + +) diff --git a/ext/standard/var.c b/ext/standard/var.c index acb1d40..4f94ec3 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -957,6 +957,10 @@ again: php_var_serialize_string(buf, ZSTR_VAL(key), ZSTR_LEN(key)); } + if (Z_ISREF_P(data) && Z_REFCOUNT_P(data) == 1) { + ZVAL_UNREF(data); + } + /* we should still add element even if it's not OK, * since we already wrote the length of the array before */ if ((Z_TYPE_P(data) == IS_ARRAY && Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc))

« previous php.cvs (#92159) next »