php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81638 a set of functions about file state will not work correctly
Submitted: 2021-11-19 12:37 UTC Modified: 2021-11-19 15:52 UTC
From: inhann at qq dot com Assigned: cmb (profile)
Status: Not a bug Package: Streams related
PHP Version: 7.4.26 OS: linux
Private report: No CVE-ID: None
 [2021-11-19 12:37 UTC] inhann at qq dot com
Description:
------------
any function whose definition is started with `FileFunction(PHP_FN` in `ext/standard/filestat.c` will call the system call ,stat , in linux , which will finally return false  when recieving a path with more than 20 symbolic links 

the affected functions are as follows:
fileperms、fileinode、filesize、fileowner、filegroup、fileatime、filemtime、filectime、filetype、is_writable、is_readable、is_executable、is_file、is_dir、is_link、file_exists ........

you can read `ext/standard/filestat.c` to find more

Test script:
---------------
<?php 
$f = "/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/proc/self/root/etc/passwd";
var_dump(file_exists($f));
readfile($f);

?>
file exists but `file_exists($f)` return false , is_writable、is_readable、is_executable、is_file、is_dir、is_link、file_exists ...... will return false as well

Expected result:
----------------
bool(true)
the content of /etc/passwd

Actual result:
--------------
bool(false)
the content of /etc/passwd

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-11-19 15:52 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-11-19 15:52 UTC] cmb@php.net
This is not a bug, but rather a deliberate restriction to avoid
infinite loops or broken symlinks[1].  LINK_MAX is 32[2], though,
not 20.

[1] <https://github.com/php/php-src/blob/php-7.4.26/Zend/zend_virtual_cwd.c#L912-L913>
[2] <https://github.com/php/php-src/blob/php-7.4.26/Zend/zend_virtual_cwd.c#L495>
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Jan 22 22:03:37 2022 UTC