com php-src: Fix bug #62373 (serialize() generates wrong reference to the object): ext/standard/tests/serialize/bug62373.phpt ext/standard/var.c
| From: | Moriyoshi Koizumi | Date: | Mon, 25 Jun 2012 10:14:19 +0000 |
| Subject: | com php-src: Fix bug #62373 (serialize() generates wrong reference to the object): ext/standard/tests/serialize/bug62373.phpt ext/standard/var.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-69465@lists.php.net to get a copy of this message | ||
Commit: 91e1df704eed40325fd963a308e466bbbf96184f
Author: Moriyoshi Koizumi <mozo@mozo.jp> Mon, 25 Jun 2012 19:13:23 +0900
Parents: ad641950b3d047fc20729b7a18c62b414622cc79
Branches: PHP-5.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=91e1df704eed40325fd963a308e466bbbf96184f
Log:
Fix bug #62373 (serialize() generates wrong reference to the object)
Bugs:
https://bugs.php.net/62373
Changed paths:
A ext/standard/tests/serialize/bug62373.phpt
M ext/standard/var.c
Diff:
diff --git a/ext/standard/tests/serialize/bug62373.phpt b/ext/standard/tests/serialize/bug62373.phpt
new file mode 100644
index 0000000..666c33e
--- /dev/null
+++ b/ext/standard/tests/serialize/bug62373.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Bug #62373 (serialize() generates wrong reference to the object)
+--FILE--
+<?php
+class A {}
+class B {}
+
+$size_of_ce = (((int)(log(PHP_INT_MAX) / log(2)) + 1 == 32 ? 368: 680) + 15) & ~15;
+$dummy = array();
+$b = new B();
+$period = $size_of_ce << 5;
+for ($i = 0; $i < $period * 3; $i++) {
+ $a = new A();
+ $s = unserialize(serialize(array($b, $a)));
+ if ($s[0] === $s[1]) {
+ echo "OOPS\n";
+ break;
+ }
+ $dummy[] = $a;
+}
+
+echo "OK\n";
+?>
+--EXPECT--
+OK
diff --git a/ext/standard/var.c b/ext/standard/var.c
index c6126e9..735d0a7 100644
--- a/ext/standard/var..c
+++ b/ext/standard/var.c
@@ -541,12 +541,9 @@ static inline int php_add_var_hash(HashTable *var_hash, zval *var, void
*var_old
/* relies on "(long)" being a perfect hash function for data pointers,
* however the actual identity of an object has had to be determined
- * by its object handle and the class entry since 5.0. */
+ * by its object handle since 5.0. */
if ((Z_TYPE_P(var) == IS_OBJECT) && Z_OBJ_HT_P(var)->get_class_entry) {
- p = smart_str_print_long(id + sizeof(id) - 1,
- (((size_t)Z_OBJCE_P(var) << 5)
- | ((size_t)Z_OBJCE_P(var) >> (sizeof(long) * 8 - 5)))
- + (long) Z_OBJ_HANDLE_P(var));
+ p = smart_str_print_long(id + sizeof(id) - 1, (long) Z_OBJ_HANDLE_P(var));
*(--p) = 'O';
len = id + sizeof(id) - 1 - p;
} else {