|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-08-13 13:09 UTC] rawataman6525 at gmail dot com
Description: ------------ Hi, I was just playing around with php simplexml function and found an unexpected behaviour in this function. so to reproduce this 1. create a folder and put php file with this content <?php $FILE = "test/"; $path = "/home/aman/".$FILE."poc.xml"; echo simplexml_load_file($path); ?> 2. change /home/aman to your home directory and then change test/ to your folder that you've created in first step 3. Create two file poc.xml and poc-2.xml now run the above script `php poc.php` output will be the content of poc.xml file as expected now change the add `poc-1.xml%00` after test/ in the above script and now as we should get error like this `simplexml_load_file(): I/O warning : failed to load external entity` but due to special character we simplexml function only read path befor %00 and after it whatever it is does not matter and poc-1.xml file will be loaded successfully Test script: --------------- $FILE = "test/"; $path = "/home/aman/".$FILE."poc.xml"; echo simplexml_load_file($path); Expected result: ---------------- PHP Warning: simplexml_load_file(): I/O warning : failed to load external entity Actual result: -------------- file opened successfully without expected error PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 03:00:01 2025 UTC |
Actually, the path is silently truncated in xmlParseURI() which may be regarded as bug in libxml2. We could catch that early, though, and bail out: ext/libxml/libxml.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/libxml/libxml.c b/ext/libxml/libxml.c index c871cb89bd..6e450377f5 100644 --- a/ext/libxml/libxml.c +++ b/ext/libxml/libxml.c @@ -308,6 +308,9 @@ static void *php_libxml_streams_IO_open_wrapper(const char *filename, const char int isescaped=0; xmlURI *uri; + if (strstr(filename, "%00")) { + return NULL; + } uri = xmlParseURI(filename); if (uri && (uri->scheme == NULL || Stas, what do you think?