Handle one case the previous patch did not account for: If
unserialization of data fails, we should still register a ref
source.
Also add an extra test for a reference between two typed properties,
as this used to be handled incorrectly earlier.
echo $e->getMessage(), "\n";
}
+$s = <<<'STR'
+O:4:"Test":1:{s:4:"prop";a:1:{i:0;R:2;
+STR;
+var_dump(unserialize($s));
+
?>
---EXPECT--
+--EXPECTF--
Cannot assign stdClass to property Test::$prop of type int
+
+Notice: unserialize(): Error at offset 38 of 38 bytes in %s on line %d
+bool(false)
public int $b;
}
+class E {
+ public $a;
+ public int $b;
+}
+
class C {
public int $a;
public string $b;
var_dump(unserialize('O:1:"A":2:{s:1:"a";i:1;s:1:"b";R:2;}'));
var_dump(unserialize('O:1:"B":2:{s:1:"a";i:1;s:1:"b";R:2;}'));
+var_dump(unserialize('O:1:"E":2:{s:1:"a";i:1;s:1:"b";R:2;}'));
try {
var_dump(unserialize('O:1:"A":2:{s:1:"a";N;s:1:"b";R:2;}'));
["b"]=>
&int(1)
}
+object(E)#1 (2) {
+ ["a"]=>
+ &int(1)
+ ["b"]=>
+ &int(1)
+}
Cannot assign null to property A::$a of type int
Cannot assign null to property B::$b of type int
Cannot assign int to property C::$b of type string
}
if (!php_var_unserialize_internal(data, p, max, var_hash, 0)) {
+ if (info && Z_ISREF_P(data)) {
+ /* Add type source even if we failed to unserialize.
+ * The data is still stored in the property. */
+ ZEND_REF_ADD_TYPE_SOURCE(Z_REF_P(data), info);
+ }
zval_ptr_dtor(&key);
goto failure;
}