1
0
mirror of https://github.com/Intervention/image.git synced 2025-09-01 18:02:45 +02:00

Merge pull request #1255 from Intervention/bugfix/maximum-path-length

Fix bug with very long file/path names
This commit is contained in:
Oliver Vogel
2024-01-14 08:46:31 +01:00
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -12,12 +12,16 @@ class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterfac
{ {
public function decode(mixed $input): ImageInterface|ColorInterface 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'); throw new DecoderException('Unable to decode input');
} }
try { try {
if (! @is_file($input)) { if (!@is_file($input)) {
throw new DecoderException('Unable to decode input'); throw new DecoderException('Unable to decode input');
} }
} catch (Exception) { } catch (Exception) {

View File

@@ -16,6 +16,10 @@ class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterfac
throw new DecoderException('Unable to decode input'); throw new DecoderException('Unable to decode input');
} }
if (strlen($input) > PHP_MAXPATHLEN) {
throw new DecoderException('Unable to decode input');
}
try { try {
if (!@is_file($input)) { if (!@is_file($input)) {
throw new DecoderException('Unable to decode input'); throw new DecoderException('Unable to decode input');
@@ -25,7 +29,7 @@ class FilePathImageDecoder extends BinaryImageDecoder implements DecoderInterfac
} }
// decode image // decode image
$image = parent::decode(file_get_contents($input)); $image = parent::decode(file_get_contents($input));
// set file path on origin // set file path on origin
$image->origin()->setFilePath($input); $image->origin()->setFilePath($input);