From 2764736086197492cac3305b2dd906772cf03929 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CLamentXU123=E2=80=9D?= <108666168+LamentXU123@users.noreply.github.com> Date: Wed, 13 May 2026 12:31:32 +0800 Subject: [PATCH] ext/XML: Improve invalid value handling for XML_OPTION_SKIP_TAGSTART --- NEWS | 5 +++++ UPGRADING | 5 +++++ ext/xml/tests/xml_parser_set_option_errors.phpt | 4 +++- ext/xml/xml.c | 11 +++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 821dc09ad3a1..a1f175d83611 100644 --- a/NEWS +++ b/NEWS @@ -220,6 +220,11 @@ PHP NEWS . Fixed bug #49874 (ftell() and fseek() inconsistency when using stream filters). (Jakub Zelenka) +- XML: + . xml_parser_set_option() now reports invalid XML_OPTION_SKIP_TAGSTART + values more consistently and avoids an extra object-to-int conversion + warning for unsupported values. (Weilin Du) + - Zip: . Fixed ZipArchive callback being called after executor has shut down. (ilutov) diff --git a/UPGRADING b/UPGRADING index 37abc121a070..875cf4f960ce 100644 --- a/UPGRADING +++ b/UPGRADING @@ -118,6 +118,11 @@ PHP 8.6 UPGRADE NOTES . proc_open() now raises a ValueError when the $cwd argument contains null bytes. +- XML: + . xml_parser_set_option() now reports invalid XML_OPTION_SKIP_TAGSTART + values more consistently and no longer emits an extra object-to-int + conversion warning for unsupported values. + - Zip: . ZipArchive::extractTo now raises a TypeError for the files argument if one or more of the entries is not diff --git a/ext/xml/tests/xml_parser_set_option_errors.phpt b/ext/xml/tests/xml_parser_set_option_errors.phpt index fbb733423d77..00e9f871826c 100644 --- a/ext/xml/tests/xml_parser_set_option_errors.phpt +++ b/ext/xml/tests/xml_parser_set_option_errors.phpt @@ -38,6 +38,8 @@ xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, []); xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, new stdClass()); +xml_parser_set_option($xmlParser, XML_OPTION_SKIP_TAGSTART, "not numeric"); + echo "Encodings\n"; try { xml_parser_set_option($xmlParser, XML_OPTION_TARGET_ENCODING, 'Invalid Encoding'); @@ -75,7 +77,7 @@ Warning: xml_parser_set_option(): Argument #3 ($value) must be of type string|in Warning: xml_parser_set_option(): Argument #3 ($value) must be of type string|int|bool, stdClass given in %s on line %d -Warning: Object of class stdClass could not be converted to int in %s on line %d +Warning: xml_parser_set_option(): Argument #3 ($value) must be a valid integer for option XML_OPTION_SKIP_TAGSTART in %s on line %d Encodings xml_parser_set_option(): Argument #3 ($value) is not a supported target encoding diff --git a/ext/xml/xml.c b/ext/xml/xml.c index 06c7e2c196d4..b9374ebedde3 100644 --- a/ext/xml/xml.c +++ b/ext/xml/xml.c @@ -1588,8 +1588,15 @@ PHP_FUNCTION(xml_parser_set_option) /* Integer option */ case PHP_XML_OPTION_SKIP_TAGSTART: { /* The tag start offset is stored in an int */ - /* TODO Improve handling of values? */ - zend_long value_long = zval_get_long(value); + bool failed = false; + zend_long value_long = zval_try_get_long(value, &failed); + if (failed) { + if (Z_TYPE_P(value) == IS_STRING) { + php_error_docref(NULL, E_WARNING, + "Argument #3 ($value) must be a valid integer for option XML_OPTION_SKIP_TAGSTART"); + } + RETURN_FALSE; + } if (value_long < 0 || value_long > INT_MAX) { /* TODO Promote to ValueError in PHP 9.0 */ php_error_docref(NULL, E_WARNING, "Argument #3 ($value) must be between 0 and %d"