Bug #79451 [NEW]: Using DOMDocument->replaceChild on doctype causes double free (PHP 7.x)

From: Date: Sun, 05 Apr 2020 09:20:45 +0000
Subject: Bug #79451 [NEW]: Using DOMDocument->replaceChild on doctype causes double free (PHP 7.x)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-226436@lists.php.net to get a copy of this message
From: giovanni at giacobbi dot net Operating system: Linux PHP version: 7.4.4 Package: DOM XML related Bug Type: Bug Bug description:Using DOMDocument->replaceChild on doctype causes double free (PHP 7.x) Description: ------------ While attempting to change a loaded DOM document's DOCTYPE I ran into a double free crash, this happens after creating a new DOMDocumentType object using DOMImplementation and attempting to use replaceChild on the DOMDocument. Side note: *please* can you provide us with a clear and official documented way to change a loaded document doctype? something that we can do between loadHTML() and saveHTML() to change the doctype..thx. Test script: --------------- <?php $dom = new \DOMDocument(); $dom->loadHTML("<!DOCTYPE html><p>hello</p>"); $impl = new \DOMImplementation(); $dt = $impl->createDocumentType("html", "", ""); $dom->replaceChild($dt, $dom->doctype); Expected result: ---------------- DOCTYPE changed in memory representation Actual result: -------------- free(): double free detected in tcache 2 Aborted (core dumped) -- Edit bug report at https://bugs.php.net/bug.php?id=79451&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=79451&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=79451&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=79451&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=79451&r=needscript Try newer version: https://bugs.php.net/fix.php?id=79451&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=79451&r=support Expected behavior: https://bugs.php.net/fix.php?id=79451&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=79451&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=79451&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=79451&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=79451&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=79451&r=dst IIS Stability: https://bugs.php.net/fix.php?id=79451&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=79451&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=79451&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=79451&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=79451&r=mysqlcfg

« previous php.bugs (#226436) next »