Infinite loop when trying to copy "recursive" array
Open
Nobody has claimed this yet.
bug
- Dominant language
- PHP
- Stars
- 8.9k
- Forks
- 110
- PR merge metrics
- No merged PRs in 30d
Description
It would be nice if DeepCopy could detect array structures that lead to infinite loops.
$ composer info | sort -d
myclabs/deep-copy 1.10.2 Create deep copies (clones) of your objects
$ php -v
PHP 8.0.9 (cli) (built: Jul 29 2021 12:53:58) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.9, Copyright (c) Zend Technologies
segfault.php
<?php declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
use DeepCopy\DeepCopy;
$a = [];
$a[] = &$a;
$b = [
'RECURSION' => [
'data' => $a,
],
];
$deepCopy = new DeepCopy;
$deepCopy->skipUncloneable(false);
$deepCopy->copy($b);
Without Xdebug
$ php segfault.php
[1] 49178 segmentation fault (core dumped) php segfault.php
With Xdebug
$ php segfault.php
Fatal error: Uncaught Error: Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '256' frames in /tmp/segfault/vendor/myclabs/deep-copy/src/DeepCopy/TypeMatcher/TypeMatcher.php on line 27
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the issue's segfault.php reproduction with and without Xdebug, then inspect src/DeepCopy/TypeMatcher/TypeMatcher.php at line 27 and the DeepCopy copy entry point. The work is complete when recursive array structures are detected without an infinite loop or segmentation fault, while normal copying continues to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100