|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-01-08 15:21 UTC] 64796c6e69 at gmail dot com
Description:
------------
openFile() silently truncates anything after a null byte in a string. The suffix used for SplFileInfo is completely lost.
This happens in older versions as far as I tested.
Test script:
---------------
echo bad >badfile.txt
php -r 'var_dump((new SplFileInfo("badfile.txt\0goodfile.txt"))->openFile("r")->fread(3));'
Expected result:
----------------
An error about the file not existing or the null byte.
Actual result:
--------------
string(3) "bad"
Patchesfix-77431 (last revision 2019-01-09 13:29 UTC by cmb@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
Without command line: ---------------- <?php $file = "../../../../../../../../../../etc/passwd\0.txt"; var_dump((new SplFileInfo($file))->openFile("r")->fread(4)); Actual result: ---------------- string(4) "root"I completely agree. It may also make sense to reject empty paths for consistency with SplFileObject and fopen(). SplFileInfo::openFile() already throws an exception in that case, but since an empty path is never valid, I would think it makes more sense for that to happen in the constructor. php -r 'new SplFileObject("");' Fatal error: Uncaught RuntimeException: SplFileObject::__construct(): Filename cannot be empty in Command line code on line 1 php -r 'fopen("", "r");' Warning: fopen(): Filename cannot be empty in Command line code on line 1