Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite recursion when data provider provides recursive array #5614

Closed
ptomulik opened this issue Dec 11, 2023 · 5 comments
Closed

Infinite recursion when data provider provides recursive array #5614

ptomulik opened this issue Dec 11, 2023 · 5 comments
Labels
feature/data-provider Data Providers type/bug Something is broken version/10 Something affects PHPUnit 10

Comments

@ptomulik
Copy link
Contributor

ptomulik commented Dec 11, 2023

Q A
PHPUnit version >=10.0.0
PHP version 8.2.13
Installation Method Composer / PHAR

Summary

When @dataProvider method tries to return recursive array, it always fails with SEGFAULT.

Current behavior

Segmentation fault.

How to reproduce

<?php declare(strict_types=1);

use PHPUnit\Framework\TestCase;

final class RecursiveArrayTest extends TestCase {
    public static function provideRecursiveArray(): iterable {
        $array = [];
        $array[0] = &$array;
        yield [$array];
    }

    /**
     * @dataProvider provideRecursiveArray
     */
    public function testRecursiveArray(array $array): void {
        $this->assertTrue(true);
    }
}
ptomulik@tea:$ vendor/bin/phpunit tests/RecursiveArrayTest.php 
PHPUnit 10.0.0 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.13

Segmentation fault

Expected behavior

The test should pass

@ptomulik ptomulik added type/bug Something is broken version/10 Something affects PHPUnit 10 labels Dec 11, 2023
@sebastianbergmann
Copy link
Owner

You are testing with PHPUnit 10.0.0 which is not supported anymore. Do you encounter the same issue with PHPUnit 10.5.2?

@ptomulik
Copy link
Contributor Author

You are testing with PHPUnit 10.0.0 which is not supported anymore. Do you encounter the same issue with PHPUnit 10.5.2?

10.0 is the first version having this bug (9.6 seems working fine). From my experiments, it looks like all the versions >=10.0 are vulnerable.

@ptomulik
Copy link
Contributor Author

ptomulik@tea:$ vendor/bin/phpunit tests/RecursiveArrayTest.php 
PHPUnit 10.5.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.13

Segmentation fault

@sebastianbergmann sebastianbergmann changed the title SEGFAULT when providing recursive arrays Infinite recursion when data provider provides recursive array Dec 11, 2023
@sebastianbergmann
Copy link
Owner

This happens in TestCase::registerMockObjectsFromTestArguments().

We do not need this code anymore in PHPUnit 11 as data providers must be static in PHPUnit 11 and therefore can no longer create mock objects. So in PHPUnit 11 this problem will be gone.

As for PHPUnit 10, I do not considers recursive arrays important enough (IMO, they are an edge case) to spend time on fixing the implementation of TestCase::registerMockObjectsFromTestArguments(). I would consider a pull request that addresses this, of course, but I will not invest time in debugging this myself.

ptomulik added a commit to ptomulik/phpunit that referenced this issue Dec 11, 2023
ptomulik added a commit to ptomulik/phpunit that referenced this issue Dec 11, 2023
@ptomulik
Copy link
Contributor Author

See #5615

sebastianbergmann pushed a commit that referenced this issue Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/data-provider Data Providers type/bug Something is broken version/10 Something affects PHPUnit 10
Projects
None yet
Development

No branches or pull requests

2 participants