Skip to content

Commit 645815c

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix #73246: XMLReader: encoding length not checked
2 parents 7bc9df4 + 272df44 commit 645815c

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
@@ -26,6 +26,9 @@ PHP NEWS
2626
. Fixed bug #80933 (SplFileObject::DROP_NEW_LINE is broken for NUL and CR).
2727
(cmb, Nikita)
2828

29+
- XMLReader:
30+
. Fixed bug #73246 (XMLReader: encoding length not checked). (cmb)
31+
2932
29 Apr 2021, PHP 8.0.5
3033

3134
- Core:

ext/xmlreader/php_xmlreader.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,11 @@ PHP_METHOD(XMLReader, open)
862862
RETURN_THROWS();
863863
}
864864

865+
if (encoding && CHECK_NULL_PATH(encoding, encoding_len)) {
866+
php_error_docref(NULL, E_WARNING, "Encoding must not contain NUL bytes");
867+
RETURN_FALSE;
868+
}
869+
865870
valid_file = _xmlreader_get_valid_file_path(source, resolved_path, MAXPATHLEN );
866871

867872
if (valid_file) {
@@ -1037,6 +1042,11 @@ PHP_METHOD(XMLReader, XML)
10371042
RETURN_THROWS();
10381043
}
10391044

1045+
if (encoding && CHECK_NULL_PATH(encoding, encoding_len)) {
1046+
php_error_docref(NULL, E_WARNING, "Encoding must not contain NUL bytes");
1047+
RETURN_FALSE;
1048+
}
1049+
10401050
inputbfr = xmlParserInputBufferCreateMem(source, source_len, XML_CHAR_ENCODING_NONE);
10411051

10421052
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)