php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43312 php://filter URIs get mangled and make xinclude() fail
Submitted: 2007-11-16 13:42 UTC Modified: 2008-02-01 13:12 UTC
From: php at benjaminschulz dot com Assigned: chregu (profile)
Status: Wont fix Package: DOM XML related
PHP Version: 5.3CVS-2007-11-16 (CVS) OS:
Private report: No CVE-ID: None
 [2007-11-16 13:42 UTC] php at benjaminschulz dot com
Description:
------------
When using php://filter with xinclude an errornous file:// uri is 
generated and let's the xinclude fail. 

Reproduce code:
---------------
test.php
--------
<?php
echo '<pre>';

class TestFilter extends PHP_User_Filter {
    public function filter($in, $out, &$consumed, $closing) {
        while ($bucket = stream_bucket_make_writeable($in)) {
            $consumed += $bucket->datalen;
            stream_bucket_append($out, $bucket);
        }
        return PSFS_PASS_ON;
    }
}
stream_filter_register('testfilter', 'TestFilter');

$doc = new DomDocument;
$doc->load("php://filter/read=testfilter/resource=file://".dirname(__FILE__)."/test1.xml");
$doc->xinclude();
echo "works!";

test1.xml
---------
<?xml version="1.0" encoding="UTF-8"?>
<foo>
    <xi:include href="test2.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
</foo>

test2.xml
---------
<?xml version="1.0" encoding="UTF-8"?>
<bar>baz</bar>


Expected result:
----------------
"works!"

Actual result:
--------------
Warning: 
DOMDocument::xinclude(php://filter/read=testfilter/resource=file%3A/path
/to/test2.xml): failed to open stream: No such file or directory in 
/path/to/test.php on line 18
                                                                         
^- should be ":" and there are two slashes missing

Warning: DOMDocument::xinclude(): I/O warning : failed to load external 
entity "php://filter/read=testfilter/resource=file%3A/path/to/test2.xml" 
in /path/to/test.php on line 18

Warning: DOMDocument::xinclude(): could not load 
php://filter/read=testfilter/resource=file%3A/path/to/test2.xml, and no 
fallback was found in /path/to/test.php on line 18

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-02-01 13:12 UTC] rrichards@php.net
PHP URL handling for streams is not fully compatible with libxml2 URL handling and canonicalization routines.
Workaround is to use a relative path for that case:
php://filter/read=testfilter/resource=./test1.xml
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC