Commit 2cedcc59edc for php

commit 2cedcc59edc4729da353e1ca57c533bc2798ba94
Author: ndossche <7771979+ndossche@users.noreply.github.com>
Date:   Fri Oct 23 23:09:37 2026 +0200

    Fix GHSA-x8r7-mg3g-74hg: Lifetime issue in Dom\XMLDocument serialiser

diff --git a/ext/dom/tests/modern/xml/GHSA-x8r7-mg3g-74hg.phpt b/ext/dom/tests/modern/xml/GHSA-x8r7-mg3g-74hg.phpt
new file mode 100644
index 00000000000..ae30e129b50
--- /dev/null
+++ b/ext/dom/tests/modern/xml/GHSA-x8r7-mg3g-74hg.phpt
@@ -0,0 +1,23 @@
+--TEST--
+GHSA-x8r7-mg3g-74hg (Lifetime issue in Dom\XMLDocument serialiser)
+--EXTENSIONS--
+dom
+--CREDITS--
+EliseZeroTwo
+--FILE--
+<?php
+
+$doc = Dom\HTMLDocument::createFromString('<!DOCTYPE html><svg xmlns:xlink="urn:x" xlink:href="a"><g xmlns:xlink="http://www.w3.org/1999/xlink"/></svg><svg/>', LIBXML_NOERROR);
+echo $doc->saveXml(), "\n";
+
+$doc = Dom\XMLDocument::createFromString('<cat><kitten xmlns:cat="meow"/></cat>');
+$doc->documentElement->setAttributeNS('meow', 'miau', 'miaou');
+echo $doc->saveXml(), "\n";
+
+?>
+--EXPECT--
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="urn:x" xmlns:ns1="http://www.w3.org/1999/xlink" ns1:href="a"><g xmlns:xlink="http://www.w3.org/1999/xlink"/></svg><svg xmlns="http://www.w3.org/2000/svg"/></body></html>
+<?xml version="1.0" encoding="UTF-8"?>
+<cat xmlns:ns1="meow" ns1:miau="miaou"><kitten xmlns:cat="meow"/></cat>
diff --git a/ext/dom/xml_serializer.c b/ext/dom/xml_serializer.c
index bd7e8bf6aa8..c3c763d4c3c 100644
--- a/ext/dom/xml_serializer.c
+++ b/ext/dom/xml_serializer.c
@@ -244,6 +244,10 @@ static void dom_xml_ns_prefix_map_add(
 	} else if (GC_REFCOUNT(list) > 1) {
 		GC_DELREF(list);
 		list = zend_array_dup(list);
+		ZEND_HASH_PACKED_FOREACH_VAL(list, zval *val) {
+			/* Descendant does not own the data. */
+			DOM_Z_UNOWNED(val, Z_PTR_P(val));
+		} ZEND_HASH_FOREACH_END();
 		zend_hash_str_update_ptr(map->ht, (const char *) ns, ns_length, list);
 	}