php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81698 getType()->getName() crashes on dynamic properties
Submitted: 2021-12-04 17:55 UTC Modified: 2021-12-06 11:06 UTC
From: richiruizmartinez at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Reflection related
PHP Version: 7.4.3 OS: Ubuntu 20.04
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: richiruizmartinez at gmail dot com
New email:
PHP Version: OS:

 

 [2021-12-04 17:55 UTC] richiruizmartinez at gmail dot com
Description:
------------
When I run the code shown below, PHP generates a segmentation fault. The object $o has a dynamic property $p. When trying to find out the type of $p, the segmentation fault appears.

Test script:
---------------
class C { }
$o = new C();
$o->p = 0;
$ro = new \ReflectionObject($o);
foreach ($ro->getProperties() as $rp) {
   echo $rp->getType()->getName();
}


Expected result:
----------------
segmentation fault (core dumped)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-12-04 19:57 UTC] nikic@php.net
-Type: Security +Type: Bug
 [2021-12-04 22:23 UTC] richiruizmartinez at gmail dot com
getType()->__toString() also crashes:

$foo = new stdClass;
$foo->bar = 1;
var_dump((new ReflectionObject($foo))->getProperties()[0]->getType()->__toString());
 [2021-12-05 18:45 UTC] ilutov@php.net
-Status: Open +Status: Feedback
 [2021-12-05 18:45 UTC] ilutov@php.net
Hm, both examples don't segfault on 3v4l.

https://3v4l.org/fPM7s
https://3v4l.org/2nH6H

Does it require opcache or something to crash? I tried it on master with opcache and it also worked fine. Can you provide more information about your environment?
 [2021-12-06 08:03 UTC] richiruizmartinez at gmail dot com
-Status: Feedback +Status: Open -PHP Version: 7.4.26 +PHP Version: 7.4.3
 [2021-12-06 08:03 UTC] richiruizmartinez at gmail dot com
The exact PHP version is 7.4.3

You can view the errors here:

https://asciinema.org/a/453949
 [2021-12-06 11:06 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-12-06 11:06 UTC] cmb@php.net
> The exact PHP version is 7.4.3

Then consider to update to the latest 7.4.26, where this issue
apparently has been fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC