Skip to content

Commit c7980b3

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix GH-25434: C14NFile() skips namespace relinking on success
2 parents 794fea4 + 73d71aa commit c7980b3

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎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)