[php-src] Issue #20439: xml_set_default_handler() does not properly handle special characters in attributes when passing data to callback
| From: | bawolff | Date: | Mon, 10 Nov 2025 05:59:47 +0000 |
| Subject: | [php-src] Issue #20439: xml_set_default_handler() does not properly handle special characters in attributes when passing data to callback | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251197@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/20439
Author: bawolff
### Description
The following code:
```php
<?php
$x = xml_parser_create_ns( 'utf-8' );
xml_set_default_handler( $x, function( $p, $data ) { echo $data; } );
xml_parse( $x, "<foo attr1='\"<"'
attr2=\""<\"></foo>" , true );
```
Resulted in this output:
```
<foo attr1=""<"" attr2=""<"></foo>
```
But I expected this output instead:
```
<foo attr1=""<""
attr2=""<"></foo>
```
Note: This requires you to compile php without expat. If expat support is compiled in, then the bug
does not happen.
Basically, attributes with
" or < get mangled resulting in invalid
XML.
### PHP Version
```plain
PHP 8.4.14 (cli) (built: Nov 8 2025 21:25:55) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.14, Copyright (c) Zend Technologies
with Zend OPcache v8.4.14, Copyright (c), by Zend Technologies
```
### Operating System
_No response_