Skip to content

Commit

Permalink
[11.x] Fix PHP_MAXPATHLEN check for strings slightly smaller then PHP…
Browse files Browse the repository at this point in the history
…_MAXPATHLEN (#51850)

* Fix `PHP_MAXPATHLEN` test

This test was incorrect because it does not take into account the paths that are prefixed in the FileViewFinder. This means that we have so far tested a path that is significantly longer than `PHP_MAXPATHLEN`. As we cannot reliably access the path, we approach `PHP_MAXPATHLEN` and test all file names from `PHP_MAXPATHLEN - 200` to `PHP_MAXPATHLEN + 1`.

* Fix `PHP_MAXPATHLEN` check

The previous test was wrong. In fact, `PHP_MAXPATHLEN` is not the maximum length of a file, but `PHP_MAXPATHLEN - 1`. This is checked internally in the PHP source code and if the file is PHP_MAXPATHLEN characters long or longer, the error is thrown in Open-Base-Dir [1].

The problem was incompletely fixed here: #50962

[1] https://github.com/php/php-src/blob/7c860628cd2bf11ee867bfb41b3fd0314c5177c5/main/fopen_wrappers.c#L301
  • Loading branch information
joshuaruesweg authored Jun 20, 2024
1 parent d0c5a40 commit d2ed1b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/View/FileViewFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ protected function findInPaths($name, $paths)
foreach ($this->getPossibleViewFiles($name) as $file) {
$viewPath = $path.'/'.$file;

if (strlen($viewPath) <= PHP_MAXPATHLEN && $this->files->exists($viewPath)) {
if (strlen($viewPath) < (PHP_MAXPATHLEN - 1) && $this->files->exists($viewPath)) {
return $viewPath;
}
}
Expand Down
8 changes: 5 additions & 3 deletions tests/Integration/View/BladeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ public function test_rendering_blade_long_maxpathlen_string_with_exact_length()
$this->assertNotFalse($iniSet, 'Could not set config for open_basedir.');
}

$longString = str_repeat('x', PHP_MAXPATHLEN);
for ($i = PHP_MAXPATHLEN - 200; $i <= PHP_MAXPATHLEN + 1; $i++) {
$longString = str_repeat('x', $i);

$result = Blade::render($longString);
$result = Blade::render($longString);

$this->assertSame($longString, $result);
$this->assertSame($longString, $result);
}
}

public function test_rendering_blade_component_instance()
Expand Down

0 comments on commit d2ed1b0

Please sign in to comment.