xref: /PHP-8.2/ext/com_dotnet/tests/bug77177.phpt (revision 98288a27)
1--TEST--
2Bug #77177 (Serializing or unserializing COM objects crashes)
3--EXTENSIONS--
4com_dotnet
5--SKIPIF--
6<?php
7if (!class_exists("dotnet")) die("skip mscoree not available");
8?>
9--FILE--
10<?php
11$com = new COM("WScript.Shell");
12$dotnet = new DOTNET("mscorlib", "System.Collections.Stack");
13$variant = new VARIANT;
14foreach ([$com, $dotnet, $variant] as $object) {
15    try {
16        serialize($object);
17    } catch (Exception $ex) {
18        echo "Exception: {$ex->getMessage()}\n";
19    }
20}
21
22$strings = ['C:3:"com":0:{}', 'C:6:"dotnet":0:{}', 'C:7:"variant":0:{}'];
23foreach ($strings as $string) {
24    try {
25        unserialize($string);
26    } catch (Exception $ex) {
27        echo "Exception: {$ex->getMessage()}\n";
28    }
29}
30
31$strings = ['O:3:"com":0:{}', 'O:6:"dotnet":0:{}', 'O:7:"variant":0:{}'];
32foreach ($strings as $string) {
33    try {
34        unserialize($string);
35    } catch (Exception $ex) {
36        echo "Exception: {$ex->getMessage()}\n";
37    }
38}
39?>
40--EXPECTF--
41Exception: Serialization of 'com' is not allowed
42Exception: Serialization of 'dotnet' is not allowed
43Exception: Serialization of 'variant' is not allowed
44Exception: Unserialization of 'com' is not allowed
45Exception: Unserialization of 'dotnet' is not allowed
46Exception: Unserialization of 'variant' is not allowed
47Exception: Unserialization of 'com' is not allowed
48Exception: Unserialization of 'dotnet' is not allowed
49Exception: Unserialization of 'variant' is not allowed
50