php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81208 Segmentation fault while create newInstance from attribute
Submitted: 2021-06-29 19:20 UTC Modified: -
From: saysdragon007 at gmail dot com Assigned:
Status: Closed Package: Reflection related
PHP Version: 8.0.7 OS: MacOS
Private report: No CVE-ID: None
 [2021-06-29 19:20 UTC] saysdragon007 at gmail dot com
Description:
------------
I got a segmentation error when I warmed up the cache in Symphony and made a typo in the property argument.
As you can see i pass 3 arguments into Annotation. But If you pass less or more named arguments into annotation or change its order - you got "Expected result".

the annotation  used as reference: https://github.com/doctrine/orm/blob/2.9.x/lib/Doctrine/ORM/Mapping/Column.php

Test script:
---------------
<?php

#[Attribute(Attribute::TARGET_PROPERTY)]
class MyAnnotation
{
    public function __construct(public bool $nullable = false) {}
}

class MyClass {
    #[MyAnnotation(name: "my_name", type: "integer", nullable: asdasdasd)]
    public $property;
}

$z = new ReflectionClass(MyClass::class);

foreach($z->getProperty("property")->getAttributes() as $attribute)
{
    $attribute->newInstance();
}

Expected result:
----------------
Fatal error: Uncaught Error: Undefined constant "asdasdasd" in index.php:18
Stack trace:
#0 index.php(18): ReflectionAttribute->newInstance()
#1 {main}
  thrown in index.php on line 18

Actual result:
--------------
zsh: segmentation fault  php index.php

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-07-01 11:38 UTC] git@php.net
Automatic comment on behalf of nikic
Revision: https://github.com/php/php-src/commit/b976bc44f16fa34450bf92345067b267c52cd7ee
Log: Fixed bug #81208
 [2021-07-01 11:38 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 21:01:32 2024 UTC