Skip to content

Commit 629c501

Browse files
committed
ext/XML: Improve invalid value handling for XML_OPTION_SKIP_TAGSTART
1 parent c0af268 commit 629c501

4 files changed

Lines changed: 34 additions & 2 deletions

File tree

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ PHP NEWS
220220
. Fixed bug #49874 (ftell() and fseek() inconsistency when using stream
221221
filters). (Jakub Zelenka)
222222

223+
- XML:
224+
. xml_parser_set_option() now reports invalid XML_OPTION_SKIP_TAGSTART
225+
values more consistently and avoids an extra object-to-int conversion
226+
warning for unsupported values. (Weilin Du)
227+
223228
- Zip:
224229
. Fixed ZipArchive callback being called after executor has shut down.
225230
(ilutov)

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ PHP 8.6 UPGRADE NOTES
118118
. proc_open() now raises a ValueError when the $cwd argument contains
119119
null bytes.
120120

121+
- XML:
122+
. xml_parser_set_option() now reports invalid XML_OPTION_SKIP_TAGSTART
123+
values more consistently and no longer emits an extra object-to-int
124+
conversion warning for unsupported values.
125+
121126
- Zip:
122127
. ZipArchive::extractTo now raises a TypeError for the
123128
files argument if one or more of the entries is not

ext/xml/tests/xml_parser_set_option_errors.phpt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, []);
3838

3939
xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, new stdClass());
4040

41+
var_dump(xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, "123test"));
42+
var_dump(xml_parser_get_option($xmlParser, XML_OPTION_SKIP_TAGSTART));
43+
44+
var_dump(xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, 1.5));
45+
var_dump(xml_parser_get_option($xmlParser, XML_OPTION_SKIP_TAGSTART));
46+
4147
echo "Encodings\n";
4248
try {
4349
xml_parser_set_option($xmlParser, XML_OPTION_TARGET_ENCODING, 'Invalid Encoding');
@@ -75,7 +81,13 @@ Warning: xml_parser_set_option(): Argument #3 ($value) must be of type string|in
7581

7682
Warning: xml_parser_set_option(): Argument #3 ($value) must be of type string|int|bool, stdClass given in %s on line %d
7783

78-
Warning: Object of class stdClass could not be converted to int in %s on line %d
84+
bool(true)
85+
int(123)
86+
87+
Warning: xml_parser_set_option(): Argument #3 ($value) must be of type string|int|bool, float given in %s on line %d
88+
bool(true)
89+
int(1)
90+
7991
Encodings
8092
xml_parser_set_option(): Argument #3 ($value) is not a supported target encoding
8193

ext/xml/xml.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,17 @@ PHP_FUNCTION(xml_parser_set_option)
15881588
/* Integer option */
15891589
case PHP_XML_OPTION_SKIP_TAGSTART: {
15901590
/* The tag start offset is stored in an int */
1591-
/* TODO Improve handling of values? */
1591+
switch (Z_TYPE_P(value)) {
1592+
case IS_FALSE:
1593+
case IS_TRUE:
1594+
case IS_LONG:
1595+
case IS_DOUBLE:
1596+
case IS_STRING:
1597+
break;
1598+
default:
1599+
RETURN_FALSE;
1600+
}
1601+
15921602
zend_long value_long = zval_get_long(value);
15931603
if (value_long < 0 || value_long > INT_MAX) {
15941604
/* TODO Promote to ValueError in PHP 9.0 */

0 commit comments

Comments
 (0)