From 43ebcb5824c3505cdb6691135cd4f62861cc5610 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 30 Mar 2022 17:55:47 +0200 Subject: [PATCH] Fix handling of true return value for loadRootServerFile, fixes #10675 --- .../Repository/ComposerRepository.php | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 12fa41860e96..196c7e38f1fc 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -657,7 +657,10 @@ private function getProviderNames(): array $this->loadRootServerFile(); if (null === $this->providerListing) { - $this->loadProviderListings($this->loadRootServerFile()); + $data = $this->loadRootServerFile(); + if (is_array($data)) { + $this->loadProviderListings($data); + } } if ($this->lazyProvidersUrl) { @@ -713,7 +716,10 @@ private function whatProvides(string $name, array $acceptableStabilities = null, } if (null === $this->providerListing) { - $this->loadProviderListings($this->loadRootServerFile()); + $data = $this->loadRootServerFile(); + if (is_array($data)) { + $this->loadProviderListings($data); + } } $useLastModifiedCheck = false; @@ -1020,9 +1026,9 @@ private function getPackagesJsonUrl(): string /** * @param int|null $rootMaxAge - * @return array + * @return array<'providers'|'provider-includes'|'packages'|'providers-url'|'notify-batch'|'search'|'mirrors'|'providers-lazy-url'|'metadata-url'|'available-packages'|'available-package-patterns', mixed>|true */ - protected function loadRootServerFile(?int $rootMaxAge = null): array + protected function loadRootServerFile(?int $rootMaxAge = null) { if (null !== $this->rootData) { return $this->rootData; @@ -1163,6 +1169,9 @@ private function canonicalizeUrl(string $url): string private function loadDataFromServer(): array { $data = $this->loadRootServerFile(); + if (true === $data) { + throw new \LogicException('loadRootServerFile should not return true during initialization'); + } return $this->loadIncludes($data); } @@ -1579,6 +1588,9 @@ private function asyncFetchFile(string $filename, string $cacheKey, ?string $las private function initializePartialPackages(): void { $rootData = $this->loadRootServerFile(); + if ($rootData === true) { + return; + } $this->partialPackagesByName = array(); foreach ($rootData['packages'] as $package => $versions) {