From 80907cd75d039509c5edfbe8ef6a05f4de7a3d98 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 13 Oct 2022 14:07:06 +0200 Subject: [PATCH] Ensure files are readable before reading in JsonFile, fixes #11077 --- src/Composer/Json/JsonFile.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index e850f5ec8..206ee662e 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -93,6 +93,9 @@ class JsonFile if ($this->httpDownloader) { $json = $this->httpDownloader->get($this->path)->getBody(); } else { + if (!is_readable($this->path)) { + throw new \RuntimeException('The file "'.$this->path.'" is not readable.'); + } if ($this->io && $this->io->isDebug()) { $realpathInfo = ''; $realpath = realpath($this->path); @@ -190,6 +193,9 @@ class JsonFile */ public function validateSchema(int $schema = self::STRICT_SCHEMA, ?string $schemaFile = null): bool { + if (!is_readable($this->path)) { + throw new \RuntimeException('The file "'.$this->path.'" is not readable.'); + } $content = file_get_contents($this->path); $data = json_decode($content);