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

Composer doesn't gracefully handle config.json being unreadable #11077

Closed
dkarlovi opened this issue Sep 23, 2022 · 3 comments
Closed

Composer doesn't gracefully handle config.json being unreadable #11077

dkarlovi opened this issue Sep 23, 2022 · 3 comments
Labels
Milestone

Comments

@dkarlovi
Copy link

My composer.json:

N/A

Output of composer diagnose:

PHP Fatal error:  Uncaught TypeError: json_decode(): Argument #1 ($json) must be of type string, bool given in /usr/share/php/Composer/Json/JsonFile.php:194
Stack trace:
#0 /usr/share/php/Composer/Json/JsonFile.php(194): json_decode()
#1 /usr/share/php/Composer/Factory.php(721): Composer\Json\JsonFile->validateSchema()
#2 /usr/share/php/Composer/Factory.php(186): Composer\Factory::validateJsonSchema()
#3 /usr/share/php/Composer/Factory.php(330): Composer\Factory::createConfig()
#4 /usr/share/php/Composer/Factory.php(625): Composer\Factory->createComposer()
#5 /usr/share/php/Composer/Console/Application.php(498): Composer\Factory::create()
#6 /usr/share/php/Composer/Console/Application.php(443): Composer\Console\Application->getComposer()
#7 /usr/share/php/Composer/Console/Application.php(388): Composer\Console\Application->hintCommonErrors()
#8 /usr/share/php/Composer/vendor/symfony/console/Application.php(171): Composer\Console\Application->doRun()
#9 /usr/share/php/Composer/Console/Application.php(138): Symfony\Component\Console\Application->run()
#10 /usr/bin/composer(89): Composer\Console\Application->run()
#11 {main}
  thrown in /usr/share/php/Composer/Json/JsonFile.php on line 194

When I run this command:

I get the following output:

Same as above

And I expected this to happen:

Warn about being unable to read $COMPOSER_HOME/config.json

Reproducer

$ chmod 000 ~/.composer/config.json
$ composer diagnose
@ciaranmcnulty
Copy link

ciaranmcnulty commented Sep 23, 2022

Looks like Factory validates the file before creating a JsonConfigSource - if the file is manipulated or read later it gets checked for readability but this won't happen at the early Factory stage

https://github.com/composer/composer/blame/main/src/Composer/Config/JsonConfigSource.php#L217

@Seldaek Seldaek added this to the 2.4 milestone Oct 13, 2022
@Seldaek Seldaek added the Bug label Oct 13, 2022
@ferdiusa
Copy link

The commit by Seldaek used is_readable instead of Filesystem::isReadable and will not work on network shares (SMB). see #8231. Please update to Filesystem::isReadable and verify again, thank you!

@Seldaek
Copy link
Member

Seldaek commented Oct 25, 2022

@ferdiusa ah good catch, sorry about that. Fixed in 8554731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants