Skip to content

Commit

Permalink
Merge pull request #1255 from Intervention/bugfix/maximum-path-length
Browse files Browse the repository at this point in the history
Fix bug with very long file/path names
  • Loading branch information
olivervogel committed Jan 14, 2024
2 parents aafc9b6 + c990371 commit 9531e0e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Drivers/Gd/Decoders/FilePathImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion src/Drivers/Imagick/Decoders/FilePathImageDecoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public function decode(mixed $input): ImageInterface|ColorInterface
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');
Expand All @@ -25,7 +29,7 @@ public function decode(mixed $input): ImageInterface|ColorInterface
}

// 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);
Expand Down

0 comments on commit 9531e0e

Please sign in to comment.