From 45c707cddffb3c9fc9746124d387d287c579be13 Mon Sep 17 00:00:00 2001 From: lazerg Date: Fri, 13 Nov 2026 07:16:02 +0500 Subject: [PATCH 1/2] Fix GH-25434: C14NFile() skips namespace relinking on success --- ext/dom/node.c | 2 +- ext/dom/tests/modern/xml/gh25434.phpt | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 ext/dom/tests/modern/xml/gh25434.phpt diff --git a/ext/dom/node.c b/ext/dom/node.c index 867d166edb47..3b2ca849130b 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -2331,7 +2331,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ bytes = xmlOutputBufferClose(buf); if (mode == 1 && (ret >= 0)) { - RETURN_LONG(bytes); + RETVAL_LONG(bytes); } } diff --git a/ext/dom/tests/modern/xml/gh25434.phpt b/ext/dom/tests/modern/xml/gh25434.phpt new file mode 100644 index 000000000000..22d8e8b3b79a --- /dev/null +++ b/ext/dom/tests/modern/xml/gh25434.phpt @@ -0,0 +1,22 @@ +--TEST-- +GH-25434 (C14NFile() on a Dom\XMLDocument leaves the document changed and leaks memory) +--CREDITS-- +Wonseok Oh (marinelay) +--EXTENSIONS-- +dom +--FILE-- +'); +var_dump($doc->C14NFile(__DIR__ . '/gh25434.xml')); +echo file_get_contents(__DIR__ . '/gh25434.xml'), "\n"; +echo $doc->saveXml(), "\n"; +?> +--CLEAN-- + +--EXPECT-- +int(48) + + + From eb0d34f2e4059522789dbe7de9da5cb441fbd866 Mon Sep 17 00:00:00 2001 From: lazerg Date: Fri, 13 Nov 2026 10:20:05 +0500 Subject: [PATCH 2/2] Return false when xmlOutputBufferClose() fails in C14NFile() --- ext/dom/node.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ext/dom/node.c b/ext/dom/node.c index 3b2ca849130b..e982cd6a13b7 100644 --- a/ext/dom/node.c +++ b/ext/dom/node.c @@ -2331,7 +2331,11 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ bytes = xmlOutputBufferClose(buf); if (mode == 1 && (ret >= 0)) { - RETVAL_LONG(bytes); + if (bytes < 0) { + RETVAL_FALSE; + } else { + RETVAL_LONG(bytes); + } } }