|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71993 DOMDocument::loadHTML ignores anything after a null byte
Submitted: 2016-04-08 19:18 UTC Modified: 2016-04-13 07:29 UTC
From: raul at raulr dot net Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 7.0.5 OS: Linux
Private report: No CVE-ID: None
 [2016-04-08 19:18 UTC] raul at raulr dot net
DOMDocument::loadHTML() stops processing the source string after a null byte (U+0000) without issuing any exception or warning.

I have tested that this happens in PHP versions 5.5.34, 5.6.20 and 7.0.5.

Test script:

$html = <<<EOD
<!DOCTYPE html>
<div>Pre NULL byte</div>
<div>Post NULL byte</div>

$dom = new \DOMDocument('1.0');
$dom->validateOnParse = true;
echo $dom->saveHTML();

Expected result:
<!DOCTYPE html>
<html><body><div>Pre NULL byte</div>

<div>Post NULL byte</div>

Actual result:
<!DOCTYPE html>
<html><body><div>Pre NULL byte</div></body></html>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-04-13 07:29 UTC]
-Status: Open +Status: Not a bug
 [2016-04-13 07:29 UTC]
Thanks for the report. The input comes as a binary safe string in PHP, then we reevaluate it using xmlStrlen(). But even without it, libxml2 will retain same behavior just silently stopping. Thus it is not a bug in PHP, this should be reevaluated once libxml2 has a better HTML5support. Please see also this couple of links

PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Sep 28 13:01:23 2020 UTC