Skip to content

Commit 956576b

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-17223: Memory leak in libxml encoding handling
2 parents 250e0ff + 7be950f commit 956576b

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ PHP NEWS
6161
- Iconv:
6262
. Fixed bug GH-17047 (UAF on iconv filter failure). (nielsdos)
6363

64+
- LibXML:
65+
. Fixed bug GH-17223 (Memory leak in libxml encoding handling). (nielsdos)
66+
6467
- MBString:
6568
. Fixed bug GH-17112 (Macro redefinitions). (nielsdos, cmb)
6669

ext/dom/tests/gh17223.phpt

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
GH-17223 (Memory leak in libxml encoding handling)
3+
--EXTENSIONS--
4+
dom
5+
--FILE--
6+
<?php
7+
$doc = new DOMDocument("1.0", "Shift-JIS");
8+
@$doc->save("%00");
9+
echo "Done\n";
10+
?>
11+
--EXPECT--
12+
Done

ext/libxml/libxml.c

+8-3
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,11 @@ php_libxml_output_buffer_create_filename(const char *URI,
562562
char *unescaped = NULL;
563563

564564
if (URI == NULL)
565-
return(NULL);
565+
goto err;
566566

567567
if (strstr(URI, "%00")) {
568568
php_error_docref(NULL, E_WARNING, "URI must not contain percent-encoded NUL bytes");
569-
return NULL;
569+
goto err;
570570
}
571571

572572
puri = xmlParseURI(URI);
@@ -587,7 +587,7 @@ php_libxml_output_buffer_create_filename(const char *URI,
587587
}
588588

589589
if (context == NULL) {
590-
return(NULL);
590+
goto err;
591591
}
592592

593593
/* Allocate the Output buffer front-end. */
@@ -599,6 +599,11 @@ php_libxml_output_buffer_create_filename(const char *URI,
599599
}
600600

601601
return(ret);
602+
603+
err:
604+
/* Similarly to __xmlOutputBufferCreateFilename we should also close the encoder on failure. */
605+
xmlCharEncCloseFunc(encoder);
606+
return NULL;
602607
}
603608

604609
static void _php_libxml_free_error(void *ptr)

0 commit comments

Comments
 (0)