Skip to content

Commit bae1fe4

Browse files
committed
ext/XML: Improve invalid value handling for XML_OPTION_SKIP_TAGSTART
1 parent 2764736 commit bae1fe4

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

ext/xml/tests/xml_parser_set_option_errors.phpt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, []);
3838

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

41-
xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, "not numeric");
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));
4246

4347
echo "Encodings\n";
4448
try {
@@ -77,7 +81,13 @@ Warning: xml_parser_set_option(): Argument #3 ($value) must be of type string|in
7781

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

80-
Warning: xml_parser_set_option(): Argument #3 ($value) must be a valid integer for option XML_OPTION_SKIP_TAGSTART in %s on line %d
84+
Warning: A non-numeric value encountered in %s on line %d
85+
bool(true)
86+
int(123)
87+
88+
Warning: xml_parser_set_option(): Argument #3 ($value) must be of type string|int|bool, float given in %s on line %d
89+
bool(true)
90+
int(1)
8191
Encodings
8292
xml_parser_set_option(): Argument #3 ($value) is not a supported target encoding
8393

ext/xml/xml.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,15 +1588,11 @@ 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-
bool failed = false;
1592-
zend_long value_long = zval_try_get_long(value, &failed);
1593-
if (failed) {
1594-
if (Z_TYPE_P(value) == IS_STRING) {
1595-
php_error_docref(NULL, E_WARNING,
1596-
"Argument #3 ($value) must be a valid integer for option XML_OPTION_SKIP_TAGSTART");
1597-
}
1591+
if (Z_TYPE_P(value) == IS_ARRAY || Z_TYPE_P(value) == IS_OBJECT || Z_TYPE_P(value) == IS_RESOURCE) {
15981592
RETURN_FALSE;
15991593
}
1594+
1595+
zend_long value_long = zval_get_long(value);
16001596
if (value_long < 0 || value_long > INT_MAX) {
16011597
/* TODO Promote to ValueError in PHP 9.0 */
16021598
php_error_docref(NULL, E_WARNING, "Argument #3 ($value) must be between 0 and %d"

0 commit comments

Comments
 (0)