Skip to content

Commit 1e9e397

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: ext/libxml: Fixed custom external entity loader returning an invalid resource leading to a confusing TypeError message
2 parents fed948d + 61f704f commit 1e9e397

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ PHP NEWS
1717
. Fixed GH-18243 imagettftext() overflow/underflow on font size value.
1818
(David Carlier)
1919

20+
- libxml:
21+
. Fixed custom external entity loader returning an invalid resource leading
22+
to a confusing TypeError message. (Girgias)
23+
2024
- OpenSSL:
2125
. Fix memory leak in openssl_sign() when passing invalid algorithm.
2226
(nielsdos)

ext/libxml/libxml.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -769,13 +769,18 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
769769
is_string:
770770
resource = Z_STRVAL(retval);
771771
} else if (Z_TYPE(retval) == IS_RESOURCE) {
772-
php_stream *stream;
773-
php_stream_from_zval_no_verify(stream, &retval);
774-
if (stream == NULL) {
775-
php_libxml_ctx_error(context,
776-
"The user entity loader callback '%s' has returned a "
777-
"resource, but it is not a stream",
778-
ZSTR_VAL(LIBXML(entity_loader_callback).function_handler->common.function_name));
772+
php_stream *stream = (php_stream*)zend_fetch_resource2_ex(&retval, NULL, php_file_le_stream(), php_file_le_pstream());
773+
if (UNEXPECTED(stream == NULL)) {
774+
zval callable;
775+
zend_get_callable_zval_from_fcc(&LIBXML(entity_loader_callback), &callable);
776+
zend_string *callable_name = zend_get_callable_name(&callable);
777+
zend_string *func_name = get_active_function_or_method_name();
778+
zend_type_error(
779+
"%s(): The user entity loader callback \"%s\" has returned a resource, but it is not a stream",
780+
ZSTR_VAL(func_name), ZSTR_VAL(callable_name));
781+
zend_string_release(func_name);
782+
zend_string_release(callable_name);
783+
zval_ptr_dtor(&callable);
779784
} else {
780785
/* TODO: allow storing the encoding in the stream context? */
781786
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;

ext/libxml/tests/libxml_get_external_entity_loader_error_callback_name.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ try {
3737

3838
?>
3939
--EXPECT--
40-
string(73) "DOMDocument::validate(): supplied resource is not a valid stream resource"
40+
string(122) "DOMDocument::validate(): The user entity loader callback "Handler::handle" has returned a resource, but it is not a stream"

0 commit comments

Comments
 (0)