瀏覽代碼

Test unserialization with properties

Stefan Siegl 11 年之前
父節點
當前提交
73d022cca1
共有 3 個文件被更改,包括 37 次插入6 次删除
  1. 17 2
      tests/serialize_001.phpt
  2. 12 0
      tests/serialize_basic.phpt
  3. 8 4
      v8js.cc

+ 17 - 2
tests/serialize_001.phpt

@@ -21,15 +21,26 @@ catch(\V8JsException $e) {
 $stored = 'O:8:"V8Object":0:{}';
 $stored = 'O:8:"V8Object":0:{}';
 
 
 try {
 try {
-    $obj = unserialize($stored);
+    $obj2 = unserialize($stored);
 }
 }
 catch(\V8JsException $e) {
 catch(\V8JsException $e) {
     var_dump(get_class($e));
     var_dump(get_class($e));
     var_dump($e->getMessage());
     var_dump($e->getMessage());
 }
 }
 
 
-$v8->foo = $obj;
+var_dump(isset($obj2));
+
+$stored = 'O:8:"V8Object":1:{s:3:"foo";i:23;}';
+
+try {
+    $obj = unserialize($stored);
+}
+catch(\V8JsException $e) {
+    var_dump(get_class($e));
+    var_dump($e->getMessage());
+}
 
 
+var_dump(isset($obj3));
 
 
 ?>
 ?>
 ===EOF===
 ===EOF===
@@ -42,4 +53,8 @@ string(13) "V8JsException"
 string(54) "You cannot serialize or unserialize V8Object instances"
 string(54) "You cannot serialize or unserialize V8Object instances"
 string(13) "V8JsException"
 string(13) "V8JsException"
 string(54) "You cannot serialize or unserialize V8Object instances"
 string(54) "You cannot serialize or unserialize V8Object instances"
+bool(false)
+string(13) "V8JsException"
+string(54) "You cannot serialize or unserialize V8Object instances"
+bool(false)
 ===EOF===
 ===EOF===

+ 12 - 0
tests/serialize_basic.phpt

@@ -25,6 +25,16 @@ catch(\V8JsException $e) {
     var_dump($e->getMessage());
     var_dump($e->getMessage());
 }
 }
 
 
+$stored = 'O:4:"V8Js":1:{s:3:"foo";i:23;}';
+
+try {
+    $b = unserialize($stored);
+}
+catch(\V8JsException $e) {
+    var_dump(get_class($e));
+    var_dump($e->getMessage());
+}
+
 ?>
 ?>
 ===EOF===
 ===EOF===
 --EXPECT--
 --EXPECT--
@@ -32,4 +42,6 @@ string(13) "V8JsException"
 string(50) "You cannot serialize or unserialize V8Js instances"
 string(50) "You cannot serialize or unserialize V8Js instances"
 string(13) "V8JsException"
 string(13) "V8JsException"
 string(50) "You cannot serialize or unserialize V8Js instances"
 string(50) "You cannot serialize or unserialize V8Js instances"
+string(13) "V8JsException"
+string(50) "You cannot serialize or unserialize V8Js instances"
 ===EOF===
 ===EOF===

+ 8 - 4
v8js.cc

@@ -385,12 +385,16 @@ static HashTable *php_v8js_v8_get_properties(zval *object TSRMLS_DC) /* {{{ */
 			/* the garbage collector is running, don't create more zvals */
 			/* the garbage collector is running, don't create more zvals */
 			return NULL;
 			return NULL;
 		}
 		}
-		if (obj->ctx == NULL) {
-			/* Half-constructed object.  Shouldn't happen, but be safe. */
-			return NULL;
-		}
+
 		ALLOC_HASHTABLE(obj->properties);
 		ALLOC_HASHTABLE(obj->properties);
 		zend_hash_init(obj->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
 		zend_hash_init(obj->properties, 0, NULL, ZVAL_PTR_DTOR, 0);
+
+		if (!obj->ctx) {
+			/* Half-constructed object, probably due to unserialize call.
+			 * Just pass back properties hash so unserialize can write to
+			 * it (instead of crashing the engine). */
+			return obj->properties;
+		}
 	} else {
 	} else {
 		zend_hash_clean(obj->properties);
 		zend_hash_clean(obj->properties);
 	}
 	}