Protect against stack overflow if the user derives from Message. (#8248)
* Protect against stack overflow if the user derives from Message.
* For pure-PHP, change error into an exception.
diff --git a/php/tests/GeneratedClassTest.php b/php/tests/GeneratedClassTest.php
index c0de0ba..d1836a9 100644
--- a/php/tests/GeneratedClassTest.php
+++ b/php/tests/GeneratedClassTest.php
@@ -24,6 +24,13 @@
use PBEmpty\PBEcho\TestEmptyPackage;
use Php\Test\TestNamespace;
+# This is not allowed, but we at least shouldn't crash.
+class C extends \Google\Protobuf\Internal\Message {
+ public function __construct($data = null) {
+ parent::__construct($data);
+ }
+}
+
class GeneratedClassTest extends TestBase
{
@@ -1724,6 +1731,16 @@
}
#########################################################
+ # Test that we don't crash if users create their own messages.
+ #########################################################
+
+ public function testUserDefinedClass() {
+ # This is not allowed, but at least we shouldn't crash.
+ $this->expectException(Exception::class);
+ $p = new C();
+ }
+
+ #########################################################
# Test no segfault when error happens
#########################################################