Skip to content

Commit 39dc317

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: libxml: Fix some deprecations regarding input buffer/parser handling
2 parents 7610527 + 4401b03 commit 39dc317

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ PHP NEWS
2828
. Fixed bug GH-20502 (\Uri\WhatWg\Url crashes (SEGV) when parsing
2929
malformed URL due to Lexbor memory corruption). (lexborisov)
3030

31+
- LibXML:
32+
. Fix some deprecations on newer libxml versions regarding input
33+
buffer/parser handling. (ndossche)
34+
3135
- Opcache:
3236
. Fixed bug GH-20329 (opcache.file_cache broken with full interned string
3337
buffer). (Arnaud)

ext/libxml/libxml.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -615,11 +615,10 @@ php_libxml_output_buffer_create_filename(const char *URI,
615615
}
616616

617617
/* Allocate the Output buffer front-end. */
618-
ret = xmlAllocOutputBuffer(encoder);
619-
if (ret != NULL) {
620-
ret->context = context;
621-
ret->writecallback = php_libxml_streams_IO_write;
622-
ret->closecallback = php_libxml_streams_IO_close;
618+
ret = xmlOutputBufferCreateIO(php_libxml_streams_IO_write, php_libxml_streams_IO_close, context, encoder);
619+
if (ret == NULL) {
620+
php_libxml_streams_IO_close(context);
621+
goto err;
623622
}
624623

625624
return ret;
@@ -806,6 +805,7 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,
806805
zend_string_release(callable_name);
807806
zval_ptr_dtor(&callable);
808807
} else {
808+
#if LIBXML_VERSION < 21400
809809
/* TODO: allow storing the encoding in the stream context? */
810810
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
811811
xmlParserInputBufferPtr pib = xmlAllocParserInputBuffer(enc);
@@ -824,6 +824,12 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,
824824
xmlFreeParserInputBuffer(pib);
825825
}
826826
}
827+
#else
828+
/* make stream not being closed when the zval is freed */
829+
GC_ADDREF(stream->res);
830+
ret = xmlNewInputFromIO(NULL, php_libxml_streams_IO_read, php_libxml_streams_IO_close, stream, 0);
831+
/* Note: if ret == NULL, the close operation will be executed, so don't DELREF stream->res upon failure! */
832+
#endif
827833
}
828834
} else if (Z_TYPE(retval) != IS_NULL) {
829835
/* retval not string nor resource nor null; convert to string */

0 commit comments

Comments
 (0)