Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/libxml: Fixed custom external entity loader returning an invalid resource leading to a confusing TypeError message #18096

Open
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -32,6 +32,10 @@ PHP NEWS
(David Carlier)
. Fix UConverter::transcode with substitutes as references. (David Carlier)

- libxml:
. Fixed custom external entity loader returning an invalid resource leading
to a confusing TypeError message. (Girgias)

- Mbstring:
. Fixed bug GH-17989 (mb_output_handler crash with unset
http_output_conv_mimetypes). (nielsdos)
19 changes: 12 additions & 7 deletions ext/libxml/libxml.c
Original file line number Diff line number Diff line change
@@ -793,13 +793,18 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
is_string:
resource = Z_STRVAL(retval);
} else if (Z_TYPE(retval) == IS_RESOURCE) {
php_stream *stream;
php_stream_from_zval_no_verify(stream, &retval);
if (stream == NULL) {
php_libxml_ctx_error(context,
"The user entity loader callback '%s' has returned a "
"resource, but it is not a stream",
ZSTR_VAL(LIBXML(entity_loader_callback).function_handler->common.function_name));
php_stream *stream = (php_stream*)zend_fetch_resource2_ex(&retval, NULL, php_file_le_stream(), php_file_le_pstream());
if (UNEXPECTED(stream == NULL)) {
zval callable;
zend_get_callable_zval_from_fcc(&LIBXML(entity_loader_callback), &callable);
zend_string *callable_name = zend_get_callable_name(&callable);
zend_string *func_name = get_active_function_or_method_name();
zend_type_error(
"%s(): The user entity loader callback \"%s\" has returned a resource, but it is not a stream",
ZSTR_VAL(func_name), ZSTR_VAL(callable_name));
zend_string_release(func_name);
zend_string_release(callable_name);
zval_ptr_dtor(&callable);
} else {
/* TODO: allow storing the encoding in the stream context? */
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
Original file line number Diff line number Diff line change
@@ -40,4 +40,4 @@ $file = __DIR__ . '/db.dba';
unlink($file);
?>
--EXPECT--
string(73) "DOMDocument::validate(): supplied resource is not a valid stream resource"
string(122) "DOMDocument::validate(): The user entity loader callback "Handler::handle" has returned a resource, but it is not a stream"
Loading
Oops, something went wrong.