From c9903717abbc5c8895c9062fb6ae8cc012d69327 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Mon, 8 Jan 2024 16:40:01 +0100 Subject: [PATCH] Fix bug PHP enconters problems on some machines when is_file() in FilePathImageDecoders receive values that are longer than the maximum-path-length of the host. This fix checks if the input is in this maximum path length. --- src/Drivers/Gd/Decoders/FilePathImageDecoder.php | 8 ++++++-- src/Drivers/Imagick/Decoders/FilePathImageDecoder.php | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Drivers/Gd/Decoders/FilePathImageDecoder.php b/src/Drivers/Gd/Decoders/FilePathImageDecoder.php index 48a69e0f..2a46ba53 100644 --- a/src/Drivers/Gd/Decoders/FilePathImageDecoder.php +++ b/src/Drivers/Gd/Decoders/FilePathImageDecoder.php @@ -12,12 +12,16 @@ class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterfac { public function decode(mixed $input): ImageInterface|ColorInterface { - if (! is_string($input)) { + if (!is_string($input)) { + throw new DecoderException('Unable to decode input'); + } + + if (strlen($input) > PHP_MAXPATHLEN) { throw new DecoderException('Unable to decode input'); } try { - if (! @is_file($input)) { + if (!@is_file($input)) { throw new DecoderException('Unable to decode input'); } } catch (Exception) { diff --git a/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php b/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php index 1b76e0a1..7a728dc4 100644 --- a/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php +++ b/src/Drivers/Imagick/Decoders/FilePathImageDecoder.php @@ -16,6 +16,10 @@ class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterfac throw new DecoderException('Unable to decode input'); } + if (strlen($input) > PHP_MAXPATHLEN) { + throw new DecoderException('Unable to decode input'); + } + try { if (!@is_file($input)) { throw new DecoderException('Unable to decode input'); @@ -25,7 +29,7 @@ class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterfac } // decode image - $image = parent::decode(file_get_contents($input)); + $image = parent::decode(file_get_contents($input)); // set file path on origin $image->origin()->setFilePath($input);