Skip to content

Bump libxml version, deprecate libxml_disable_entity_loader() #5867

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

Closed
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion build/php.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2010,7 +2010,7 @@ dnl
dnl Common setup macro for libxml.
dnl
AC_DEFUN([PHP_SETUP_LIBXML], [
PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.7.6])
PKG_CHECK_MODULES([LIBXML], [libxml-2.0 >= 2.9.0])

PHP_EVAL_INCLINE($LIBXML_CFLAGS)
PHP_EVAL_LIBLINE($LIBXML_LIBS, $1)
Expand Down
1 change: 1 addition & 0 deletions ext/libxml/libxml.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function libxml_get_errors(): array {}

function libxml_clear_errors(): void {}

/** @deprecated */
function libxml_disable_entity_loader(bool $disable = true): bool {}

function libxml_set_external_entity_loader(?callable $resolver_function): bool {}
4 changes: 2 additions & 2 deletions ext/libxml/libxml_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 2d793e5134ea8633c432f03d20c1d8b80a05795b */
* Stub hash: ded229511dc2bc3912d35b8055c0fd69420baff0 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_libxml_set_streams_context, 0, 1, IS_VOID, 0)
ZEND_ARG_INFO(0, context)
Expand Down Expand Up @@ -42,7 +42,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(libxml_get_last_error, arginfo_libxml_get_last_error)
ZEND_FE(libxml_get_errors, arginfo_libxml_get_errors)
ZEND_FE(libxml_clear_errors, arginfo_libxml_clear_errors)
ZEND_FE(libxml_disable_entity_loader, arginfo_libxml_disable_entity_loader)
ZEND_DEP_FE(libxml_disable_entity_loader, arginfo_libxml_disable_entity_loader)
ZEND_FE(libxml_set_external_entity_loader, arginfo_libxml_set_external_entity_loader)
ZEND_FE_END
};
24 changes: 0 additions & 24 deletions ext/libxml/tests/bug54138_1.phpt

This file was deleted.

2 changes: 2 additions & 0 deletions ext/libxml/tests/libxml_disable_entity_loader.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ echo "Done\n";
?>
--EXPECTF--
bool(true)

Deprecated: Function libxml_disable_entity_loader() is deprecated in %s on line %d
bool(false)

Warning: DOMDocument::loadXML(): I/O warning : failed to load external entity "%s" in %s on line %d
Expand Down
53 changes: 53 additions & 0 deletions ext/libxml/tests/libxml_entity_loading_disabled_by_default.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
--TEST--
libxml_disable_entity_loader()
--SKIPIF--
<?php
if (!extension_loaded('libxml')) die('skip libxml extension not available');
if (!extension_loaded('dom')) die('skip dom extension not available');
--FILE--
<?php

$xml = <<<EOT
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE test [<!ENTITY xxe SYSTEM "XXE_URI">]>
<foo>&xxe;</foo>
EOT;

$dir = str_replace('\\', '/', __DIR__);
$xml = str_replace('XXE_URI', $dir . '/libxml_disable_entity_loader_payload.txt', $xml);

function parseXML1($xml) {
$doc = new DOMDocument();
$doc->loadXML($xml, 0);
return $doc->saveXML();
}

function parseXML2($xml) {
return simplexml_load_string($xml);
}

function parseXML3($xml) {
$p = xml_parser_create();
xml_parse_into_struct($p, $xml, $vals, $index);
xml_parser_free($p);
return var_export($vals, true);
}

function parseXML4($xml) {
// This is the only time we enable external entity loading.
return simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOENT);
}

var_dump(strpos(parseXML1($xml), 'SECRET_DATA') === false);
var_dump(strpos(parseXML2($xml), 'SECRET_DATA') === false);
var_dump(strpos(parseXML3($xml), 'SECRET_DATA') === false);
var_dump(strpos(parseXML4($xml), 'SECRET_DATA') === false);

echo "Done\n";
?>
--EXPECTF--
bool(true)
bool(true)
bool(true)
bool(false)
Done