Skip to content

Commit f8d682f

Browse files
committed
ext/com: add tests for sa_proxy variant error cases
1 parent 79871b4 commit f8d682f

4 files changed

Lines changed: 97 additions & 13 deletions

File tree

ext/com_dotnet/tests/bug77177.phpt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,19 @@
22
Bug #77177 (Serializing or unserializing COM objects crashes)
33
--EXTENSIONS--
44
com_dotnet
5-
--SKIPIF--
6-
<?php
7-
if (!class_exists("dotnet")) die("skip mscoree not available");
8-
?>
95
--FILE--
106
<?php
117
$com = new COM("WScript.Shell");
12-
$dotnet = new DOTNET("mscorlib", "System.Collections.Stack");
138
$variant = new VARIANT;
14-
foreach ([$com, $dotnet, $variant] as $object) {
9+
foreach ([$com, $variant] as $object) {
1510
try {
1611
serialize($object);
1712
} catch (Exception $ex) {
1813
echo "Exception: {$ex->getMessage()}\n";
1914
}
2015
}
2116

22-
$strings = ['C:3:"com":0:{}', 'C:6:"dotnet":0:{}', 'C:7:"variant":0:{}'];
17+
$strings = ['C:3:"com":0:{}', 'C:7:"variant":0:{}'];
2318
foreach ($strings as $string) {
2419
try {
2520
unserialize($string);
@@ -28,7 +23,7 @@ foreach ($strings as $string) {
2823
}
2924
}
3025

31-
$strings = ['O:3:"com":0:{}', 'O:6:"dotnet":0:{}', 'O:7:"variant":0:{}'];
26+
$strings = ['O:3:"com":0:{}', 'O:7:"variant":0:{}'];
3227
foreach ($strings as $string) {
3328
try {
3429
unserialize($string);
@@ -37,13 +32,10 @@ foreach ($strings as $string) {
3732
}
3833
}
3934
?>
40-
--EXPECTF--
35+
--EXPECT--
4136
Exception: Serialization of 'com' is not allowed
42-
Exception: Serialization of 'dotnet' is not allowed
4337
Exception: Serialization of 'variant' is not allowed
4438
Exception: Unserialization of 'com' is not allowed
45-
Exception: Unserialization of 'dotnet' is not allowed
4639
Exception: Unserialization of 'variant' is not allowed
4740
Exception: Unserialization of 'com' is not allowed
48-
Exception: Unserialization of 'dotnet' is not allowed
4941
Exception: Unserialization of 'variant' is not allowed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #77177 (Serializing or unserializing COM objects crashes, dotnet class)
3+
--EXTENSIONS--
4+
com_dotnet
5+
--SKIPIF--
6+
<?php
7+
if (!class_exists("dotnet")) die("skip mscoree not available");
8+
?>
9+
--FILE--
10+
<?php
11+
$dotnet = new DOTNET("mscorlib", "System.Collections.Stack");
12+
try {
13+
serialize($dotnet);
14+
} catch (Exception $ex) {
15+
echo "Exception: {$ex->getMessage()}\n";
16+
}
17+
18+
try {
19+
unserialize('C:6:"dotnet":0:{}');
20+
} catch (Exception $ex) {
21+
echo "Exception: {$ex->getMessage()}\n";
22+
}
23+
24+
try {
25+
unserialize('O:6:"dotnet":0:{}');
26+
} catch (Exception $ex) {
27+
echo "Exception: {$ex->getMessage()}\n";
28+
}
29+
?>
30+
--EXPECT--
31+
Exception: Serialization of 'dotnet' is not allowed
32+
Exception: Unserialization of 'dotnet' is not allowed
33+
Exception: Unserialization of 'dotnet' is not allowed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
com_safearray_proxy errors
3+
--EXTENSIONS--
4+
com_dotnet
5+
--FILE--
6+
<?php
7+
8+
$binding_string = ['aaa','bbb','ccc'];
9+
$v = new VARIANT( $binding_string, VT_ARRAY );
10+
var_dump($v);
11+
12+
try {
13+
var_dump(isset($v->hello));
14+
} catch (Throwable $e) {
15+
echo $e::class, ': ', $e->getMessage(), "\n";
16+
}
17+
18+
try {
19+
var_dump($v->hello);
20+
} catch (Throwable $e) {
21+
echo $e::class, ': ', $e->getMessage(), "\n";
22+
}
23+
24+
try {
25+
$v->hello = 'blah';
26+
var_dump($v);
27+
} catch (Throwable $e) {
28+
echo $e::class, ': ', $e->getMessage(), "\n";
29+
}
30+
31+
try {
32+
unset($v->hello);
33+
var_dump($v);
34+
} catch (Throwable $e) {
35+
echo $e::class, ': ', $e->getMessage(), "\n";
36+
}
37+
38+
try {
39+
$c = clone $v;
40+
var_dump($c);
41+
} catch (Throwable $e) {
42+
echo $e::class, ': ', $e->getMessage(), "\n";
43+
}
44+
45+
try {
46+
$s = serialize($v);
47+
var_dump($s);
48+
} catch (Throwable $e) {
49+
echo $e::class, ': ', $e->getMessage(), "\n";
50+
}
51+
?>
52+
--EXPECT--
53+
object(variant)#1 (0) {
54+
}
55+
bool(false)
56+
com_exception: this variant has no properties
57+
com_exception: this variant has no properties
58+
Error: Cannot delete properties from a COM object
59+
Error: Trying to clone an uncloneable object of class variant
60+
Exception: Serialization of 'variant' is not allowed

ext/com_dotnet/tests/variant_no_clone.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Prevent cloning of Variant types as it's broken
33
--EXTENSIONS--
44
com_dotnet
5-
65
--FILE--
76
<?php
87

0 commit comments

Comments
 (0)