Skip to content

Commit e71036c

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #80268: loadHTML() truncates at NUL bytes
2 parents f17b2a7 + 7bc1c0c commit e71036c

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ PHP NEWS
1313
- COM:
1414
. Fixed bug #62474 (com_event_sink crashes on certain arguments). (cmb)
1515

16+
- DOM:
17+
. Fixed bug #80268 (loadHTML() truncates at NUL bytes). (cmb)
18+
1619
- IMAP:
1720
. Fixed bug #76618 (segfault on imap_reopen). (girgias)
1821
. Fixed bug #80239 (imap_rfc822_write_address() leaks memory). (cmb)

ext/dom/document.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1840,7 +1840,6 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
18401840
}
18411841
ctxt = htmlCreateFileParserCtxt(source, NULL);
18421842
} else {
1843-
source_len = xmlStrlen((xmlChar *) source);
18441843
if (ZEND_SIZE_T_INT_OVFL(source_len)) {
18451844
php_error_docref(NULL, E_WARNING, "Input string is too long");
18461845
RETURN_FALSE;

ext/dom/tests/bug80268.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #80268 (loadHTML() truncates at NUL bytes)
3+
--SKIPIF--
4+
<?php require_once('skipif.inc'); ?>
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument;
8+
$doc->loadHTML("<p>foo\0bar</p>");
9+
$html = $doc->saveHTML();
10+
var_dump(strpos($html, '<p>foo</p>') !== false);
11+
12+
file_put_contents(__DIR__ . '/80268.html', "<p>foo\0bar</p>");
13+
$doc = new DOMDocument;
14+
$doc->loadHTMLFile(__DIR__ . '/80268.html');
15+
$html = $doc->saveHTML();
16+
var_dump(strpos($html, '<p>foo</p>') !== false);
17+
?>
18+
--CLEAN--
19+
<?php
20+
unlink(__DIR__ . '/80268.html');
21+
?>
22+
--EXPECT--
23+
bool(true)
24+
bool(true)

0 commit comments

Comments
 (0)