Skip to content

Commit

Permalink
Handle invalid values better in PHP_XML_OPTION_SKIP_TAGSTART
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsdos committed Jul 6, 2024
1 parent 19358d6 commit 292e936
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions ext/xml/xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -1507,18 +1507,19 @@ PHP_FUNCTION(xml_parser_set_option)
parser->parsehuge = zend_is_true(value);
break;
/* Integer option */
case PHP_XML_OPTION_SKIP_TAGSTART:
case PHP_XML_OPTION_SKIP_TAGSTART: {
/* The tag start offset is stored in an int */
/* TODO Improve handling of values? */
parser->toffset = zval_get_long(value);
if (parser->toffset < 0) {
zend_long value_long = zval_get_long(value);
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"
" for option XML_OPTION_SKIP_TAGSTART", INT_MAX);
parser->toffset = 0;
" for option XML_OPTION_SKIP_TAGSTART", INT_MAX);
RETURN_FALSE;
}
parser->toffset = (int) value_long;
break;
}
/* String option */
case PHP_XML_OPTION_TARGET_ENCODING: {
const xml_encoding *enc;
Expand Down

0 comments on commit 292e936

Please sign in to comment.