Skip to content

Commit

Permalink
Fix PHP_MAXPATHLEN check for existing check of files for views
Browse files Browse the repository at this point in the history
A PHP warning can occur if the filename is a little less than (or equal to) \PHP_MAXPATHLEN [1] AND open_basedir [2] is configured (otherwise PHP will not throw this error [3]). By searching for the filename and appending a suffix (and also using the absolute path), we may exceed the limit. If the limit is exceeded, PHP throws a warning message [4] and Laravel aborts the execution of the code.

[1] https://www.php.net/manual/en/reserved.constants.php#constant.php-maxpathlen
[2] https://www.php.net/manual/en/ini.core.php#ini.open-basedir
[3] https://github.com/php/php-src/blob/7c860628cd2bf11ee867bfb41b3fd0314c5177c5/main/fopen_wrappers.c#L302
[4] File name is longer than the maximum allowed path length on this platform
  • Loading branch information
joshuaruesweg committed Apr 8, 2024
1 parent ca8fa7e commit 50b8885
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/View/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ protected function extractBladeViewFromString($contents)
return static::$bladeViewCache[$key];
}

if (strlen($contents) <= PHP_MAXPATHLEN && $this->factory()->exists($contents)) {
if ($this->factory()->exists($contents)) {
return static::$bladeViewCache[$key] = $contents;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/View/FileViewFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ protected function findInPaths($name, $paths)
{
foreach ((array) $paths as $path) {
foreach ($this->getPossibleViewFiles($name) as $file) {
if ($this->files->exists($viewPath = $path.'/'.$file)) {
$viewPath = $path.'/'.$file;
if (strlen($viewPath) <= PHP_MAXPATHLEN && $this->files->exists($viewPath)) {
return $viewPath;
}
}
Expand Down

0 comments on commit 50b8885

Please sign in to comment.