[php-src] Issue #11290: `DOMElement::replaceWith` causes crash
| From: | fluffycondor | Date: | Mon, 22 May 2023 07:40:08 +0000 |
| Subject: | [php-src] Issue #11290: `DOMElement::replaceWith` causes crash | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-244501@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/11290
Author: fluffycondor
### Description
This is a longstanding one (sorry for the
php-dom day!). Sometimes the same code from
#11288 causes crash on every 8.x PHP version. The code is the same, but the html markup is slightly
differs.
Live reproducing:
https://3v4l.org/KjJgQ // On every PHP 8.x version throws
DOMException: Not Found Error, hangs for 1-15 seconds, then crashes.
https://3v4l.org/FdOZR // Hangs for 1-15 seconds, crashes on
every PHP versions but PHP 8.2.6 and 8.1.19.
It's kinda related to #11289 and #11288, but this is a longstanding one. I guess this is a part
of a big picture, so I hope this would help to investigate the main cause of weird
php-dom behavior.
The following code:
```php
<?php
$html = <<<HTML
<!DOCTYPE HTML>
<html>
<body>
<p><span class="unwrap_me">Lorem</span><span
class="unwrap_me">ipsum</span><span
class="unwrap_me">dolor</span></p>
</body>
</html>
HTML;
$dom = new DOMDocument();
$dom->loadHTML($html);
$spans = iterator_to_array($dom->getElementsByTagName('span')->getIterator());
foreach ($spans as $span) {
if ('unwrap_me' === $span->getAttribute('class')) {
$span->replaceWith(...$span->childNodes);
}
}
```
results in crash on every PHP 8.x version.
### PHP Version
PHP 8.x
### Operating System
_No response_