Skip to content

Commit a939f0c

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

4 files changed

Lines changed: 30 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: 14 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,14 @@ 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+
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)
91+
7992
Encodings
8093
xml_parser_set_option(): Argument #3 ($value) is not a supported target encoding
8194

ext/xml/xml.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,12 @@ 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+
if (Z_TYPE_P(value) != IS_FALSE && Z_TYPE_P(value) != IS_TRUE &&
1592+
Z_TYPE_P(value) != IS_LONG && Z_TYPE_P(value) != IS_DOUBLE &&
1593+
Z_TYPE_P(value) != IS_STRING) {
1594+
RETURN_FALSE;
1595+
}
1596+
15921597
zend_long value_long = zval_get_long(value);
15931598
if (value_long < 0 || value_long > INT_MAX) {
15941599
/* TODO Promote to ValueError in PHP 9.0 */

0 commit comments

Comments
 (0)