xref: /PHP-7.2/ext/com_dotnet/tests/bug77177.phpt (revision 115ee49b)
1--TEST--
2Bug #77177 (Serializing or unserializing COM objects crashes)
3--SKIPIF--
4<?php
5if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
6?>
7--FILE--
8<?php
9$com = new COM("WScript.Shell");
10$dotnet = new DOTNET("mscorlib", "System.Collections.Stack");
11$variant = new VARIANT;
12foreach ([$com, $dotnet, $variant] as $object) {
13    try {
14        serialize($object);
15    } catch (Exception $ex) {
16        echo "Exception: {$ex->getMessage()}\n";
17    }
18}
19
20$strings = ['C:3:"com":0:{}', 'C:6:"dotnet":0:{}', 'C:7:"variant":0:{}'];
21foreach ($strings as $string) {
22    try {
23        unserialize($string);
24    } catch (Exception $ex) {
25        echo "Exception: {$ex->getMessage()}\n";
26    }
27}
28
29$strings = ['O:3:"com":0:{}', 'O:6:"dotnet":0:{}', 'O:7:"variant":0:{}'];
30foreach ($strings as $string) {
31    var_dump(unserialize($string));
32}
33?>
34===DONE===
35--EXPECTF--
36Exception: Serialization of 'com' is not allowed
37Exception: Serialization of 'dotnet' is not allowed
38Exception: Serialization of 'variant' is not allowed
39Exception: Unserialization of 'com' is not allowed
40Exception: Unserialization of 'dotnet' is not allowed
41Exception: Unserialization of 'variant' is not allowed
42
43Warning: Erroneous data format for unserializing 'com' in %s on line %d
44
45Notice: unserialize(): Error at offset 13 of 14 bytes in %s on line %d
46bool(false)
47
48Warning: Erroneous data format for unserializing 'dotnet' in %s on line %d
49
50Notice: unserialize(): Error at offset 16 of 17 bytes in %s on line %d
51bool(false)
52
53Warning: Erroneous data format for unserializing 'variant' in %s on line %d
54
55Notice: unserialize(): Error at offset 17 of 18 bytes in %s on line %d
56bool(false)
57===DONE===
58