From bca88bdd4b41e0f18345a23e995c3aca445ed7c6 Mon Sep 17 00:00:00 2001 From: Yanick Witschi Date: Thu, 30 Apr 2020 17:32:25 +0200 Subject: [PATCH] Fixed PoolBuilder running endlessly when packages do not exist --- .../DependencyResolver/PoolBuilder.php | 10 +++++--- .../packages-that-do-not-exist.test | 25 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/packages-that-do-not-exist.test diff --git a/src/Composer/DependencyResolver/PoolBuilder.php b/src/Composer/DependencyResolver/PoolBuilder.php index 5766f25c1..5bcccce66 100644 --- a/src/Composer/DependencyResolver/PoolBuilder.php +++ b/src/Composer/DependencyResolver/PoolBuilder.php @@ -249,6 +249,8 @@ class PoolBuilder $this->loadedNames[$name] = $constraint; } + $preLoad = $this->packagesToLoad; + foreach ($repositories as $repository) { if (empty($this->packagesToLoad)) { break; @@ -271,9 +273,11 @@ class PoolBuilder } // Make sure we empty the packagesToLoad here as it would result - // in an endless loop with non-existent packages for example - // TODO: fixme, this should only happen if it's not a new package - // $this->packagesToLoad = array(); + // in an endless loop if the array remains unchanged. + // This could happen with non-existent packages for example. + if ($preLoad == $this->packagesToLoad) { + $this->packagesToLoad = array(); + } } private function loadPackage(Request $request, PackageInterface $package, $propagateUpdate = true) diff --git a/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/packages-that-do-not-exist.test b/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/packages-that-do-not-exist.test new file mode 100644 index 000000000..b2c57f966 --- /dev/null +++ b/tests/Composer/Test/DependencyResolver/Fixtures/poolbuilder/packages-that-do-not-exist.test @@ -0,0 +1,25 @@ +--TEST-- +Test irrelevant package versions are not loaded + +--REQUEST-- +{ + "require": { + "root/req": "*" + } +} + +--FIXED-- +[ +] + +--PACKAGES-- +[ + {"name": "root/req", "version": "1.0.0", "require": {"dep/dep": "2.*"}}, + {"name": "dep/dep", "version": "2.3.4", "require": {"dep/dep3": "2.*"}} +] + +--EXPECT-- +[ + "root/req-1.0.0.0", + "dep/dep-2.3.4.0" +]