[php-src] master: ext/com: add tests for sa_proxy variant error cases

Gina Peter Banyard <[email protected]>
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Gina Peter Banyard (Girgias)
Date: 2026-06-28T21:34:25+01:00

Commit: https://github.com/php/php-src/commit/f8d682fa7056b5d7eac837a077502e8f98864b5e
Raw diff: https://github.com/php/php-src/commit/f8d682fa7056b5d7eac837a077502e8f98864b5e.diff

ext/com: add tests for sa_proxy variant error cases

Changed paths:
  A  ext/com_dotnet/tests/bug77177_dotnet.phpt
  A  ext/com_dotnet/tests/sa_proxy_errors.phpt
  M  ext/com_dotnet/tests/bug77177.phpt
  M  ext/com_dotnet/tests/variant_no_clone.phpt


Diff:

diff --git a/ext/com_dotnet/tests/bug77177.phpt b/ext/com_dotnet/tests/bug77177.phpt
index 3395f4ed810d..cba12980ad97 100644
--- a/ext/com_dotnet/tests/bug77177.phpt
+++ b/ext/com_dotnet/tests/bug77177.phpt
@@ -2,16 +2,11 @@
 Bug #77177 (Serializing or unserializing COM objects crashes)
 --EXTENSIONS--
 com_dotnet
---SKIPIF--
-<?php
-if (!class_exists("dotnet")) die("skip mscoree not available");
-?>
 --FILE--
 <?php
 $com = new COM("WScript.Shell");
-$dotnet = new DOTNET("mscorlib", "System.Collections.Stack");
 $variant = new VARIANT;
-foreach ([$com, $dotnet, $variant] as $object) {
+foreach ([$com, $variant] as $object) {
     try {
         serialize($object);
     } catch (Exception $ex) {
@@ -19,7 +14,7 @@ foreach ([$com, $dotnet, $variant] as $object) {
     }
 }
 
-$strings = ['C:3:"com":0:{}', 'C:6:"dotnet":0:{}', 'C:7:"variant":0:{}'];
+$strings = ['C:3:"com":0:{}', 'C:7:"variant":0:{}'];
 foreach ($strings as $string) {
     try {
         unserialize($string);
@@ -28,7 +23,7 @@ foreach ($strings as $string) {
     }
 }
 
-$strings = ['O:3:"com":0:{}', 'O:6:"dotnet":0:{}', 'O:7:"variant":0:{}'];
+$strings = ['O:3:"com":0:{}', 'O:7:"variant":0:{}'];
 foreach ($strings as $string) {
     try {
         unserialize($string);
@@ -37,13 +32,10 @@ foreach ($strings as $string) {
     }
 }
 ?>
---EXPECTF--
+--EXPECT--
 Exception: Serialization of 'com' is not allowed
-Exception: Serialization of 'dotnet' is not allowed
 Exception: Serialization of 'variant' is not allowed
 Exception: Unserialization of 'com' is not allowed
-Exception: Unserialization of 'dotnet' is not allowed
 Exception: Unserialization of 'variant' is not allowed
 Exception: Unserialization of 'com' is not allowed
-Exception: Unserialization of 'dotnet' is not allowed
 Exception: Unserialization of 'variant' is not allowed
diff --git a/ext/com_dotnet/tests/bug77177_dotnet.phpt b/ext/com_dotnet/tests/bug77177_dotnet.phpt
new file mode 100644
index 000000000000..d80c180ae772
--- /dev/null
+++ b/ext/com_dotnet/tests/bug77177_dotnet.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Bug #77177 (Serializing or unserializing COM objects crashes, dotnet class)
+--EXTENSIONS--
+com_dotnet
+--SKIPIF--
+<?php
+if (!class_exists("dotnet")) die("skip mscoree not available");
+?>
+--FILE--
+<?php
+$dotnet = new DOTNET("mscorlib", "System.Collections.Stack");
+try {
+    serialize($dotnet);
+} catch (Exception $ex) {
+    echo "Exception: {$ex->getMessage()}\n";
+}
+
+try {
+    unserialize('C:6:"dotnet":0:{}');
+} catch (Exception $ex) {
+    echo "Exception: {$ex->getMessage()}\n";
+}
+
+try {
+    unserialize('O:6:"dotnet":0:{}');
+} catch (Exception $ex) {
+    echo "Exception: {$ex->getMessage()}\n";
+}
+?>
+--EXPECT--
+Exception: Serialization of 'dotnet' is not allowed
+Exception: Unserialization of 'dotnet' is not allowed
+Exception: Unserialization of 'dotnet' is not allowed
diff --git a/ext/com_dotnet/tests/sa_proxy_errors.phpt b/ext/com_dotnet/tests/sa_proxy_errors.phpt
new file mode 100644
index 000000000000..99acb0c01521
--- /dev/null
+++ b/ext/com_dotnet/tests/sa_proxy_errors.phpt
@@ -0,0 +1,60 @@
+--TEST--
+com_safearray_proxy errors
+--EXTENSIONS--
+com_dotnet
+--FILE--
+<?php
+
+$binding_string = ['aaa','bbb','ccc'];
+$v = new VARIANT( $binding_string, VT_ARRAY );
+var_dump($v);
+
+try {
+    var_dump(isset($v->hello));
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+try {
+    var_dump($v->hello);
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+try {
+    $v->hello = 'blah';
+    var_dump($v);
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+try {
+    unset($v->hello);
+    var_dump($v);
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+try {
+    $c = clone $v;
+    var_dump($c);
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
+}
+
+try {
+    $s = serialize($v);
+    var_dump($s);
+} catch (Throwable $e) {
+    echo $e::class, ': ', $e->getMessage(), "\n";
+}
+?>
+--EXPECT--
+object(variant)#1 (0) {
+}
+bool(false)
+com_exception: this variant has no properties
+com_exception: this variant has no properties
+Error: Cannot delete properties from a COM object
+Error: Trying to clone an uncloneable object of class variant
+Exception: Serialization of 'variant' is not allowed
diff --git a/ext/com_dotnet/tests/variant_no_clone.phpt b/ext/com_dotnet/tests/variant_no_clone.phpt
index edb0b3996e7e..93d49235ed4e 100644
--- a/ext/com_dotnet/tests/variant_no_clone.phpt
+++ b/ext/com_dotnet/tests/variant_no_clone.phpt
@@ -2,7 +2,6 @@
 Prevent cloning of Variant types as it's broken
 --EXTENSIONS--
 com_dotnet
-
 --FILE--
 <?php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.