php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74236 XMLReader fails to read file
Submitted: 2017-03-11 01:12 UTC Modified: 2017-03-17 12:01 UTC
From: andrey at kostin dot info Assigned: cmb (profile)
Status: Not a bug Package: XML related
PHP Version: 7.1.2 OS: Ubuntu 16.04
Private report: No CVE-ID: None
 [2017-03-11 01:12 UTC] andrey at kostin dot info
Description:
------------
There are two xml files. The only difference between them is a one whitespace character in a row of ten whitespace characters. One file XMLReader processes with no problem, another one can't be read.

It works fine in PHP 5.5.35 for both files.

Test script:
---------------
<?php

$filename = 'bug1.xml';

$xml = new \XMLReader();
$xml->open($filename);

while ($xml->read()) {}

echo 'ok';


Expected result:
----------------
ok

Actual result:
--------------
PHP Warning:  XMLReader::read(): /web/www/r24/r24.ua/bug1.xml:95: parser error : Input is not proper UTF-8, indicate encoding !
Bytes: 0xD1 0x85 0x2E 0x20 in /web/www/r24/r24.ua/bug.php on line 8

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-03-11 01:15 UTC] andrey at kostin dot info
Links:
https://kostin.info/bug1.xml
https://kostin.info/bug2.xml
 [2017-03-11 15:18 UTC] andrey at kostin dot info
The following code doesn't work for both files in any PHP version (tested with 5.5.35 and 7.1.2):

<?php

$filename = 'test.xml';

$xml = fopen($filename, 'r');
$parser = xml_parser_create();

while ($data = fread($xml, 4096)) {
    xml_parse($parser, $data, feof($xml));
}

echo xml_error_string(xml_get_error_code($parser));

xml_parser_free($parser);
fclose($xml);

And all files work fine with any script with any PHP version on Debian system. It looks like a bug in libxml2, not in PHP or XMLReader. Where should it be reported?
 [2017-03-11 16:22 UTC] andrey at kostin dot info
Upgraded libxml2 to 2.9.4 from Ubuntu 16.10 packages and everything works fine now.
 [2017-03-17 12:01 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Package: XML Reader +Package: XML related -Assigned To: +Assigned To: cmb
 [2017-03-17 12:02 UTC] cmb@php.net
> Upgraded libxml2 to 2.9.4 from Ubuntu 16.10 packages and
> everything works fine now.

Indeed, that might have been a bug in libxml2, but apparently it has
been fixed, so I'm closing this ticket.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC