php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72985 Reflections with Nullable Strings producing crash.
Submitted: 2016-08-31 07:22 UTC Modified: 2016-09-01 08:22 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: andremohren at gmail dot com Assigned: nikic (profile)
Status: Closed Package: Reproducible crash
PHP Version: 7.1.0beta3 OS: Windows 7 Professional 64bit
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: andremohren at gmail dot com
New email:
PHP Version: OS:

 

 [2016-08-31 07:22 UTC] andremohren at gmail dot com
Description:
------------
When using Reflections and accessing the method return type or parameter type, php crashes might crash if the parameter is nullable.
The first checked class works flawless, the second class produces the crash.

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

function randomName(int $length) : string
{
    return implode('', array_map(function () : string {
        return chr(65 + rand(0, 25) + (rand(0, 1) === 0 ? 0 : 32));
    }, array_fill(0, $length, '')));
}

function createTestClass(int $classNameLength, int $numMethods, int $methodNameLength) : string
{
    do {
        $className = randomName($classNameLength);
    } while (class_exists($className));

    $methods = [];

    for ($m = 0; $m < $numMethods; $m++) {
        do {
            $methodName = randomName($methodNameLength);
        } while (array_key_exists($methodName, $methods));

        $methods[$methodName] = 'public function ' . $methodName . '(?string $param) : ?string { return $param; }';
    }

    eval(implode(PHP_EOL, ['class ' . $className . '{', implode(PHP_EOL, $methods), '}']));

    return $className;
}

function testClassReflections(string $className) : void
{
    $class = new ReflectionClass($className);
    $methods = [];

    foreach ($class->getMethods() as $method) {
        $parameters = [];

        foreach ($method->getParameters() as $parameter) {
            $parameters[] = $parameter->getType() . ' ' . $parameter->getName();
        }

        $methods[] = $method->getReturnType() . ' ' . $method->getName() . '(' . implode(', ', $parameters) . ')';
    }

    printf('%s { %s }' . PHP_EOL, $class->getName(), implode(', ', $methods));
}

function test(int $numClasses, int $classNameLength, int $numMethods, int $methodNameLength) : void
{

    printf('{ classes: { num: %d, length: %d }, methods: { num: %d, length: %d } }' . PHP_EOL,
        $numClasses, $classNameLength, $numMethods, $methodNameLength
    );

    for ($c = 0; $c < $numClasses; $c++) {
        testClassReflections(createTestClass($classNameLength, $numMethods, $methodNameLength));
    }
}

// This does not crash when first parameter is 1.
test(2, 10, 5, 10);



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-31 09:20 UTC] andremohren at gmail dot com
-Package: PDO Core +Package: Reproducible crash
 [2016-08-31 09:20 UTC] andremohren at gmail dot com
Corrected wrong Package - sorry.
 [2016-08-31 12:21 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2016-08-31 12:21 UTC] ab@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.


 [2016-08-31 12:29 UTC] andremohren at gmail dot com
Cannot use any of both ways to reproduce, as i cannot install software on this machine due to the lack of permissions on our business machines.
 [2016-09-01 06:39 UTC] andremohren at gmail dot com
-Status: Feedback +Status: Open
 [2016-09-01 06:39 UTC] andremohren at gmail dot com
Still open, cannot follow guide due to restrictions in my last comment.
 [2016-09-01 08:22 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2016-09-01 08:22 UTC] nikic@php.net
This issue has already been fixed, should work again for rc1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 15 12:01:29 2024 UTC