Skip to content

Commit 73d71aa

Browse files
lazergdevnexen
authored andcommitted
Fix GH-25434: C14NFile() skips namespace relinking on success
For modern DOM, dom_canonicalization() takes the xmlns:* attributes off their elements before canonicalizing and puts them back at clean_links. On success, C14NFile() returned early with RETURN_LONG(), so the declarations stayed detached and the links table leaked. It now sets the return value and falls through to the cleanup like C14N() does, returning false when xmlOutputBufferClose() fails. Close GH-25435
1 parent f983e1a commit 73d71aa

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

‎NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ PHP NEWS
3939
dom_objects_store_clone_obj when cloning Dom\Notation). (David Carlier)
4040
. Fixed bug GH-25306 (Assertion status == LXB_STATUS_OK in dom_parse_selector
4141
when lexbor allocation fails). (ndossche)
42+
. Fixed bug GH-25434 (C14NFile() on a Dom\XMLDocument leaves the document
43+
changed and leaks memory). (lazerg)
4244

4345
- GD:
4446
. Fixed use-after-free when drawing with a brush or tile image that was

‎ext/dom/node.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,11 @@ static void dom_canonicalization(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{
23312331

23322332
bytes = xmlOutputBufferClose(buf);
23332333
if (mode == 1 && (ret >= 0)) {
2334-
RETURN_LONG(bytes);
2334+
if (bytes < 0) {
2335+
RETVAL_FALSE;
2336+
} else {
2337+
RETVAL_LONG(bytes);
2338+
}
23352339
}
23362340
}
23372341

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-25434 (C14NFile() on a Dom\XMLDocument leaves the document changed and leaks memory)
3+
--CREDITS--
4+
Wonseok Oh (marinelay)
5+
--EXTENSIONS--
6+
dom
7+
--FILE--
8+
<?php
9+
$doc = Dom\XMLDocument::createFromString('<root xmlns:p="urn:p"><p:a p:x="1"/></root>');
10+
var_dump($doc->C14NFile(__DIR__ . '/gh25434.xml'));
11+
echo file_get_contents(__DIR__ . '/gh25434.xml'), "\n";
12+
echo $doc->saveXml(), "\n";
13+
?>
14+
--CLEAN--
15+
<?php
16+
@unlink(__DIR__ . '/gh25434.xml');
17+
?>
18+
--EXPECT--
19+
int(48)
20+
<root xmlns:p="urn:p"><p:a p:x="1"></p:a></root>
21+
<?xml version="1.0" encoding="UTF-8"?>
22+
<root xmlns:p="urn:p"><p:a p:x="1"/></root>

0 commit comments

Comments
 (0)