Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ext/dom/tests/gh17223.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--TEST--
GH-17223 (Memory leak in libxml encoding handling)
--EXTENSIONS--
dom
--FILE--
<?php
$doc = new DOMDocument("1.0", "Shift-JIS");
@$doc->save("%00");
echo "Done\n";
?>
--EXPECT--
Done
11 changes: 8 additions & 3 deletions ext/libxml/libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,11 +590,11 @@ php_libxml_output_buffer_create_filename(const char *URI,
char *unescaped = NULL;

if (URI == NULL)
return(NULL);
goto err;

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

puri = xmlParseURI(URI);
Expand All @@ -615,7 +615,7 @@ php_libxml_output_buffer_create_filename(const char *URI,
}

if (context == NULL) {
return(NULL);
goto err;
}

/* Allocate the Output buffer front-end. */
Expand All @@ -627,6 +627,11 @@ php_libxml_output_buffer_create_filename(const char *URI,
}

return(ret);

err:
/* Similarly to __xmlOutputBufferCreateFilename we should also close the encoder on failure. */
xmlCharEncCloseFunc(encoder);
return NULL;
}

static void _php_libxml_free_error(void *ptr)
Expand Down
Loading