Remove custom UTF-8 check function from ext/libxml

This was originally introduced as a workaround for a libxml2 bug [1].
This bug has been fixed for more than a decade [2], and we can use the
libxml2 API again. We bumped our version requirement for libxml2 beyond
that in 7.4 [3].

[1] 7e53511ec8
[2] 3ffe90ea1c
[3] 74235ca5f3

Closes GH-18706.
This commit is contained in:
Niels Dossche 2025-05-29 21:53:36 +02:00
parent 56abb316eb
commit 3cb7d1bd8a
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
4 changed files with 2 additions and 28 deletions

View file

@ -62,6 +62,7 @@ PHP 8.5 INTERNALS UPGRADE NOTES
- ext/libxml - ext/libxml
. The refcount APIs now return an `unsigned int` instead of an `int`. . The refcount APIs now return an `unsigned int` instead of an `int`.
. Removed php_libxml_xmlCheckUTF8(). Use xmlCheckUTF8() from libxml instead.
- ext/pdo - ext/pdo
. Added `php_pdo_stmt_valid_db_obj_handle()` to check if the database object . Added `php_pdo_stmt_valid_db_obj_handle()` to check if the database object

View file

@ -1236,32 +1236,6 @@ PHP_FUNCTION(libxml_get_external_entity_loader)
/* }}} */ /* }}} */
/* {{{ Common functions shared by extensions */ /* {{{ Common functions shared by extensions */
bool php_libxml_xmlCheckUTF8(const unsigned char *s)
{
size_t i;
unsigned char c;
for (i = 0; (c = s[i++]);) {
if ((c & 0x80) == 0) {
} else if ((c & 0xe0) == 0xc0) {
if ((s[i++] & 0xc0) != 0x80) {
return false;
}
} else if ((c & 0xf0) == 0xe0) {
if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) {
return false;
}
} else if ((c & 0xf8) == 0xf0) {
if ((s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80 || (s[i++] & 0xc0) != 0x80) {
return false;
}
} else {
return false;
}
}
return true;
}
zval *php_libxml_register_export(const zend_class_entry *ce, php_libxml_export_node export_function) zval *php_libxml_register_export(const zend_class_entry *ce, php_libxml_export_node export_function)
{ {
/* Initialize in case this module hasn't been loaded yet */ /* Initialize in case this module hasn't been loaded yet */

View file

@ -207,7 +207,6 @@ PHP_LIBXML_API void php_libxml_ctx_warning(void *ctx, const char *msg, ...);
PHP_LIBXML_API void php_libxml_pretend_ctx_error_ex(const char *file, int line, int column, const char *msg,...); PHP_LIBXML_API void php_libxml_pretend_ctx_error_ex(const char *file, int line, int column, const char *msg,...);
PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...); PHP_LIBXML_API void php_libxml_ctx_error(void *ctx, const char *msg, ...);
PHP_LIBXML_API void php_libxml_error_handler_va(php_libxml_error_level error_type, void *ctx, const char *msg, va_list args); PHP_LIBXML_API void php_libxml_error_handler_va(php_libxml_error_level error_type, void *ctx, const char *msg, va_list args);
PHP_LIBXML_API bool php_libxml_xmlCheckUTF8(const unsigned char *s);
PHP_LIBXML_API void php_libxml_switch_context(const zval *context, zval *oldcontext); PHP_LIBXML_API void php_libxml_switch_context(const zval *context, zval *oldcontext);
PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg); PHP_LIBXML_API void php_libxml_issue_error(int level, const char *msg);
PHP_LIBXML_API bool php_libxml_disable_entity_loader(bool disable); PHP_LIBXML_API bool php_libxml_disable_entity_loader(bool disable);

View file

@ -878,7 +878,7 @@ static xmlNodePtr to_xml_string(encodeTypePtr type, zval *data, int style, xmlNo
xmlBufferFree(in); xmlBufferFree(in);
} }
if (!php_libxml_xmlCheckUTF8(BAD_CAST(str))) { if (!xmlCheckUTF8(BAD_CAST str)) {
char *err = emalloc(new_len + 8); char *err = emalloc(new_len + 8);
char c; char c;
int i; int i;