contao-community-alliance / composer-client

This is the Contao Composer Client
http://de.contaowiki.org/Composer
27 stars 18 forks source link

TemplateFunctions.php: infinite loop #110

Closed kryptychon closed 10 years ago

kryptychon commented 10 years ago

Hi,

ContaoCommunityAlliance\Contao\Composer\TemplateFunctions

        static public function isRemoveable($name, array $required, array $replaces)
    {
        if ($name == 'contao-community-alliance/composer') {
            return false;
        }

        if (isset($required[$name])) {
            return true;
        }

        if (isset($replaces[$name])) {
            return static::isRemoveable($replaces[$name], $required, $replaces);
        }

        return false;
    }

The last if may cause an infinite loop, in my case it definitely does:

[11-Nov-2013 09:33:47 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 261900 bytes) in /var/www/users/example.com/htdocs/system/modules/!composer/ContaoCommunityAlliance/Contao/Composer/TemplateFunctions.php on line 41
[11-Nov-2013 09:34:18 UTC] PHP Fatal error:  Allowed memory size of 1073741824 bytes exhausted (tried to allocate 261900 bytes) in /var/www/users/example.com/htdocs/system/modules/!composer/ContaoCommunityAlliance/Contao/Composer/TemplateFunctions.php on line 41
[11-Nov-2013 09:36:54 UTC] PHP Fatal error:  Allowed memory size of -2147483648 bytes exhausted (tried to allocate 261900 bytes) in /var/www/users/example.com/htdocs/system/modules/!composer/ContaoCommunityAlliance/Contao/Composer/TemplateFunctions.php on line 41

I tried debuggin it by modifying the method like this:

class TemplateFunctions
{
    static $counter = 0;

    static public function isRemoveable($name, array $required, array $replaces)
    {
        if ($name == 'contao-community-alliance/composer') {
            return false;
        }

        if (isset($required[$name])) {
            return true;
        }

        if (isset($replaces[$name])) {
            static::$counter++;
            var_dump($replaces, $name);
            echo "\n";
            if(100 < static::$counter) {
                exit();
            }
            return static::isRemoveable($replaces[$name], $required, $replaces);
        }

        return false;
    }

The resulting debug info from the BE (do=composer) is

array(4) {
    ["bit3/contao-dependency-container"]=>
    string(34) "contao-legacy/dependency-container"
    ["bit3/contao-twig"]=>
    string(18) "contao-legacy/twig"
    ["metamodels/dc_general"]=>
    string(24) "contao-legacy/dc_general"
    ["bit3/contao-event-dispatcher"]=>
    string(28) "bit3/contao-event-dispatcher"
}
string(32) "bit3/contao-dependency-container"

<span title="via wiseape-contao/wa_sofortuberweisung: ~1&#13;via wiseape-contao/wa_paypalclassic: ~1&#13;via backboneit/contao-accounting: ~1" class="stability-stable">~1</span><br><span title="via wiseape-contao/wa_paypalmodule: 1.3" class="stability-stable">1.3</span><br></td>
            <td class="tl_file_list col_version"><span class="stability-stable">1.3</span></td>
            <td class="tl_file_list col_remove">
                                    <span class="to-be-removed">wird entfernt</span>
                                </td>
        </tr>
                            <tr class="even dependency"  style="display: none" onmouseover="Theme.hoverRow(this,1)" onmouseout="Theme.hoverRow(this,0)">
            <td class="tl_file_list col_type"><img src="composer/vendor/contao-community-alliance/composer/src/system/modules/%21composer/assets/images/type-contao-module.png" width="16" height="14" alt="contao-module" title="contao-module"></td>
            <td class="tl_file_list col_icon">
                <img src="system/modules/%21composer/assets/images/dependency.png" width="16" height="16" alt="Abhängigkeit von backboneit/contao-accounting" title="Abhängigkeit von backboneit/contao-accounting">              </td>
            <td class="tl_file_list col_name">
                <a href="contao/main.php?do=composer&amp;install=bit3/contao-event-dispatcher">
                    bit3/contao-event-dispatcher                    </a>
                                </td>
            <td class="tl_file_list col_requested_version">array(4) {
["bit3/contao-dependency-container"]=>
    string(34) "contao-legacy/dependency-container"
    ["bit3/contao-twig"]=>
    string(18) "contao-legacy/twig"
    ["metamodels/dc_general"]=>
    string(24) "contao-legacy/dc_general"
    ["bit3/contao-event-dispatcher"]=>
    string(28) "bit3/contao-event-dispatcher"
}
string(28) "bit3/contao-event-dispatcher"

array(4) {
    ["bit3/contao-dependency-container"]=>
    string(34) "contao-legacy/dependency-container"
    ["bit3/contao-twig"]=>
    string(18) "contao-legacy/twig"
    ["metamodels/dc_general"]=>
    string(24) "contao-legacy/dc_general"
    ["bit3/contao-event-dispatcher"]=>
    string(28) "bit3/contao-event-dispatcher"
}
string(28) "bit3/contao-event-dispatcher"
[...]

As you can see, this continues endlessly for the contao-event-dispatcher package name.

tristanlins commented 10 years ago

Fixed in 169dfba

kryptychon commented 10 years ago

thank you for the fast delivery!

tristanlins commented 10 years ago

The solution was already on my system, I have just forget to commit it >.<