Skip to content

Commit 6054a90

Browse files
committed
libxml: Fix some deprecations regarding input buffer/parser handling
Closes GH-20514.
1 parent 24f4799 commit 6054a90

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
@@ -22,6 +22,10 @@ PHP NEWS
2222
. Fixed bug GH-20483 (ASAN stack overflow with fiber.stack_size INI
2323
small value). (David Carlier)
2424

25+
- LibXML:
26+
. Fix some deprecations on newer libxml versions regarding input
27+
buffer/parser handling. (ndossche)
28+
2529
- Opcache:
2630
. Fixed bug GH-20329 (opcache.file_cache broken with full interned string
2731
buffer). (Arnaud)

ext/libxml/libxml.c

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

646646
/* Allocate the Output buffer front-end. */
647-
ret = xmlAllocOutputBuffer(encoder);
648-
if (ret != NULL) {
649-
ret->context = context;
650-
ret->writecallback = php_libxml_streams_IO_write;
651-
ret->closecallback = php_libxml_streams_IO_close;
647+
ret = xmlOutputBufferCreateIO(php_libxml_streams_IO_write, php_libxml_streams_IO_close, context, encoder);
648+
if (ret == NULL) {
649+
php_libxml_streams_IO_close(context);
650+
goto err;
652651
}
653652

654653
return(ret);
@@ -820,6 +819,7 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
820819
zend_string_release(callable_name);
821820
zval_ptr_dtor(&callable);
822821
} else {
822+
#if LIBXML_VERSION < 21400
823823
/* TODO: allow storing the encoding in the stream context? */
824824
xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
825825
xmlParserInputBufferPtr pib = xmlAllocParserInputBuffer(enc);
@@ -838,6 +838,12 @@ static xmlParserInputPtr _php_libxml_external_entity_loader(const char *URL,
838838
xmlFreeParserInputBuffer(pib);
839839
}
840840
}
841+
#else
842+
/* make stream not being closed when the zval is freed */
843+
GC_ADDREF(stream->res);
844+
ret = xmlNewInputFromIO(NULL, php_libxml_streams_IO_read, php_libxml_streams_IO_close, stream, 0);
845+
/* Note: if ret == NULL, the close operation will be executed, so don't DELREF stream->res upon failure! */
846+
#endif
841847
}
842848
} else if (Z_TYPE(retval) != IS_NULL) {
843849
/* retval not string nor resource nor null; convert to string */

0 commit comments

Comments
 (0)