Skip to content

Commit

Permalink
[11.x] Fix PHP_MAXPATHLEN check for existing check of files for views…
Browse files Browse the repository at this point in the history
… (#50962)

* Add test for \PHP_MAXPATHLEN errors

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

* Fix `PHP_MAXPATHLEN` check for existing check of files for views

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

* Update FileViewFinder.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
joshuaruesweg and taylorotwell authored Apr 9, 2024
1 parent dc6d12b commit d06bda2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion 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
4 changes: 3 additions & 1 deletion FileViewFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ 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 d06bda2

Please sign in to comment.