xref: /PHP-8.0/ext/com_dotnet/tests/bug77177.phpt (revision a555cc0b)
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--EXPECTF--
35Exception: Serialization of 'com' is not allowed
36Exception: Serialization of 'dotnet' is not allowed
37Exception: Serialization of 'variant' is not allowed
38Exception: Unserialization of 'com' is not allowed
39Exception: Unserialization of 'dotnet' is not allowed
40Exception: Unserialization of 'variant' is not allowed
41
42Warning: Erroneous data format for unserializing 'com' in %s on line %d
43
44Notice: unserialize(): Error at offset 13 of 14 bytes in %s on line %d
45bool(false)
46
47Warning: Erroneous data format for unserializing 'dotnet' in %s on line %d
48
49Notice: unserialize(): Error at offset 16 of 17 bytes in %s on line %d
50bool(false)
51
52Warning: Erroneous data format for unserializing 'variant' in %s on line %d
53
54Notice: unserialize(): Error at offset 17 of 18 bytes in %s on line %d
55bool(false)
56