Skip to content

Commit 272df44

Browse files
committed
Fix #73246: XMLReader: encoding length not checked
libxml2 expects the passed encoding to be NUL terminated, so we reject strings with NUL bytes right away. Closes GH-6899.
1 parent b8e49fe commit 272df44

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ PHP NEWS
3131
- Opcache:
3232
. Fixed bug #80900 (switch statement behavior inside function). (twosee)
3333

34+
- XMLReader:
35+
. Fixed bug #73246 (XMLReader: encoding length not checked). (cmb)
36+
3437
29 Apr 2021, PHP 7.4.18
3538

3639
- Core:

ext/xmlreader/php_xmlreader.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,11 @@ PHP_METHOD(xmlreader, open)
873873
RETURN_FALSE;
874874
}
875875

876+
if (encoding && CHECK_NULL_PATH(encoding, encoding_len)) {
877+
php_error_docref(NULL, E_WARNING, "Encoding must not contain NUL bytes");
878+
RETURN_FALSE;
879+
}
880+
876881
valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN );
877882

878883
if (valid_file) {
@@ -1055,6 +1060,11 @@ PHP_METHOD(xmlreader, XML)
10551060
RETURN_FALSE;
10561061
}
10571062

1063+
if (encoding && CHECK_NULL_PATH(encoding, encoding_len)) {
1064+
php_error_docref(NULL, E_WARNING, "Encoding must not contain NUL bytes");
1065+
RETURN_FALSE;
1066+
}
1067+
10581068
inputbfr = xmlParserInputBufferCreateMem(source, source_len, XML_CHAR_ENCODING_NONE);
10591069

10601070
if (inputbfr != NULL) {

ext/xmlreader/tests/bug73246.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #73246 (XMLReader: encoding length not checked)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded("xmlreader")) die("skip xmlreader extension not available");
6+
?>
7+
--FILE--
8+
<?php
9+
$reader = new XMLReader();
10+
$reader->open(__FILE__, "UTF\0-8");
11+
$reader->XML('<?xml version="1.0"?><root/>', "UTF\0-8");
12+
?>
13+
--EXPECTF--
14+
Warning: XMLReader::open(): Encoding must not contain NUL bytes in %s on line %d
15+
16+
Warning: XMLReader::XML(): Encoding must not contain NUL bytes in %s on line %d

0 commit comments

Comments
 (0)