Skip to content

Commit

Permalink
Merge branch 'PHP-8.1' into fix/phpgh-11950
Browse files Browse the repository at this point in the history
  • Loading branch information
SakiTakamachi committed Aug 24, 2023
2 parents a4b83c4 + ba07a0b commit cfc659a
Show file tree
Hide file tree
Showing 27 changed files with 414 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Expand Up @@ -4,7 +4,7 @@ env:
freebsd_task:
name: FREEBSD_DEBUG_NTS
freebsd_instance:
image_family: freebsd-13-0
image_family: freebsd-13-2
env:
ARCH: amd64
install_script:
Expand Down
12 changes: 0 additions & 12 deletions .github/actions/apt-x64/action.yml
Expand Up @@ -59,15 +59,3 @@ runs:
libjpeg-dev \
libpng-dev \
libfreetype6-dev
mkdir /opt/oracle
wget -nv https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip
unzip instantclient-basiclite-linuxx64.zip && rm instantclient-basiclite-linuxx64.zip
wget -nv https://download.oracle.com/otn_software/linux/instantclient/instantclient-sdk-linuxx64.zip
unzip instantclient-sdk-linuxx64.zip && rm instantclient-sdk-linuxx64.zip
mv instantclient_*_* /opt/oracle/instantclient
# interferes with libldap2 headers
rm /opt/oracle/instantclient/sdk/include/ldap.h
# fix debug build warning: zend_signal: handler was replaced for signal (2) after startup
echo DISABLE_INTERRUPT=on > /opt/oracle/instantclient/network/admin/sqlnet.ora
sudo sh -c 'echo /opt/oracle/instantclient >/etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig'
2 changes: 1 addition & 1 deletion .github/actions/install-linux-x32/action.yml
Expand Up @@ -6,7 +6,7 @@ runs:
run: |
set -x
make install
mkdir /etc/php.d
mkdir -p /etc/php.d
chmod 777 /etc/php.d
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini
echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini
Expand Down
4 changes: 1 addition & 3 deletions .github/actions/install-linux/action.yml
Expand Up @@ -6,9 +6,7 @@ runs:
run: |
set -x
sudo make install
sudo mkdir /etc/php.d
sudo mkdir -p /etc/php.d
sudo chmod 777 /etc/php.d
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini
echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini
echo extension=oci8.so > /etc/php.d/oci8.ini
echo extension=pdo_oci.so > /etc/php.d/pdo_oci.ini
17 changes: 17 additions & 0 deletions .github/actions/setup-oracle/action.yml
Expand Up @@ -11,3 +11,20 @@ runs:
--name oracle \
-h oracle \
-d gvenzl/oracle-xe:slim
mkdir /opt/oracle
wget -nv https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip
unzip instantclient-basiclite-linuxx64.zip && rm instantclient-basiclite-linuxx64.zip
wget -nv https://download.oracle.com/otn_software/linux/instantclient/instantclient-sdk-linuxx64.zip
unzip instantclient-sdk-linuxx64.zip && rm instantclient-sdk-linuxx64.zip
mv instantclient_*_* /opt/oracle/instantclient
# interferes with libldap2 headers
rm /opt/oracle/instantclient/sdk/include/ldap.h
# fix debug build warning: zend_signal: handler was replaced for signal (2) after startup
echo DISABLE_INTERRUPT=on > /opt/oracle/instantclient/network/admin/sqlnet.ora
sudo sh -c 'echo /opt/oracle/instantclient >/etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig'
sudo mkdir -p /etc/php.d
sudo chmod 777 /etc/php.d
echo extension=oci8.so > /etc/php.d/oci8.ini
echo extension=pdo_oci.so > /etc/php.d/pdo_oci.ini
21 changes: 21 additions & 0 deletions .github/nightly_matrix.php
Expand Up @@ -78,6 +78,25 @@ function get_matrix_include(array $branches) {
return $jobs;
}

function get_windows_matrix_include(array $branches) {
$jobs = [];
foreach ($branches as $branch) {
$jobs[] = [
'branch' => $branch,
'x64' => true,
'zts' => true,
'opcache' => true,
];
$jobs[] = [
'branch' => $branch,
'x64' => false,
'zts' => false,
'opcache' => false,
];
}
return $jobs;
}

$trigger = $argv[1] ?? 'schedule';
$attempt = (int) ($argv[2] ?? 1);
$discard_cache = ($trigger === 'schedule' && $attempt !== 1) || $trigger === 'workflow_dispatch';
Expand All @@ -87,6 +106,8 @@ function get_matrix_include(array $branches) {

$branches = get_branches();
$matrix_include = get_matrix_include($branches);
$windows_matrix_include = get_windows_matrix_include($branches);

echo '::set-output name=branches::' . json_encode($branches, JSON_UNESCAPED_SLASHES) . "\n";
echo '::set-output name=matrix-include::' . json_encode($matrix_include, JSON_UNESCAPED_SLASHES) . "\n";
echo '::set-output name=windows-matrix-include::' . json_encode($windows_matrix_include, JSON_UNESCAPED_SLASHES) . "\n";
17 changes: 8 additions & 9 deletions .github/workflows/nightly.yml
Expand Up @@ -11,6 +11,7 @@ jobs:
outputs:
branches: ${{ steps.set-matrix.outputs.branches }}
matrix-include: ${{ steps.set-matrix.outputs.matrix-include }}
windows-matrix-include: ${{ steps.set-matrix.outputs.windows-matrix-include }}
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -554,7 +555,7 @@ jobs:
- name: make install
run: |
sudo make install
sudo mkdir /etc/php.d
sudo mkdir -p /etc/php.d
sudo chmod 777 /etc/php.d
echo mysqli.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/mysqli.ini
echo pdo_mysql.default_socket=/var/run/mysqld/mysqld.sock > /etc/php.d/pdo_mysql.ini
Expand Down Expand Up @@ -646,17 +647,13 @@ jobs:
with:
token: ${{ secrets.ACTION_MONITORING_SLACK }}
WINDOWS:
needs: GENERATE_MATRIX
if: ${{ needs.GENERATE_MATRIX.outputs.branches != '[]' }}
strategy:
fail-fast: false
matrix:
include:
- x64: true
zts: true
opcache: true
- x64: false
zts: false
opcache: false
name: "WINDOWS_${{ matrix.x64 && 'X64' || 'X86' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}"
include: ${{ fromJson(needs.GENERATE_MATRIX.outputs.windows-matrix-include) }}
name: "${{ matrix.branch.name }}_WINDOWS_${{ matrix.x64 && 'X64' || 'X86' }}_${{ matrix.zts && 'ZTS' || 'NTS' }}"
runs-on: windows-2019
env:
PHP_BUILD_CACHE_BASE_DIR: C:\build-cache
Expand All @@ -674,6 +671,8 @@ jobs:
run: git config --global core.autocrlf false && git config --global core.eol lf
- name: git checkout
uses: actions/checkout@v3
with:
ref: ${{ matrix.branch.ref }}
- name: Setup
uses: ./.github/actions/setup-windows
- name: Build
Expand Down
22 changes: 21 additions & 1 deletion NEWS
@@ -1,6 +1,22 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.1.23
?? ??? ????, PHP 8.1.24

- Core:
. Fixed bug GH-11937 (Constant ASTs containing objects). (ilutov)

- DOM:
. Fix memory leak when setting an invalid DOMDocument encoding. (nielsdos)

- Iconv:
. Fixed build for NetBSD which still uses the old iconv signature.
(David Carlier)

- MySQLnd:
. Fixed bug GH-10270 (Invalid error message when connection via SSL fails:
"trying to connect via (null)"). (Kamil Tekiela)

31 Aug 2023, PHP 8.1.23

- CLI:
. Fixed bug GH-11716 (cli server crashes on SIGINT when compiled with
Expand Down Expand Up @@ -55,6 +71,10 @@ PHP NEWS
. Revert behaviour of receiving SIGCHLD signals back to the behaviour
before 8.1.22. (nielsdos)

- SPL:
. Fixed bug #81992 (SplFixedArray::setSize() causes use-after-free).
(nielsdos)

- Standard:
. Prevent int overflow on $decimals in number_format. (Marc Bennewitz)
. Fixed bug GH-11870 (Fix off-by-one bug when truncating tempnam prefix)
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend.h
Expand Up @@ -20,7 +20,7 @@
#ifndef ZEND_H
#define ZEND_H

#define ZEND_VERSION "4.1.23-dev"
#define ZEND_VERSION "4.1.24-dev"

#define ZEND_ENGINE_3

Expand Down
40 changes: 38 additions & 2 deletions Zend/zend_compile.c
Expand Up @@ -1458,6 +1458,35 @@ ZEND_API zend_result zend_unmangle_property_name_ex(const zend_string *name, con
}
/* }}} */

static bool array_is_const_ex(zend_array *array, uint32_t *max_checks)
{
if (zend_hash_num_elements(array) > *max_checks) {
return false;
}
*max_checks -= zend_hash_num_elements(array);

zval *element;
ZEND_HASH_FOREACH_VAL(array, element) {
if (Z_TYPE_P(element) < IS_ARRAY) {
continue;
} else if (Z_TYPE_P(element) == IS_ARRAY) {
if (!array_is_const_ex(array, max_checks)) {
return false;
}
} else {
return false;
}
} ZEND_HASH_FOREACH_END();

return true;
}

static bool array_is_const(zend_array *array)
{
uint32_t max_checks = 50;
return array_is_const_ex(array, &max_checks);
}

static bool can_ct_eval_const(zend_constant *c) {
if (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED) {
return 0;
Expand All @@ -1468,9 +1497,13 @@ static bool can_ct_eval_const(zend_constant *c) {
&& (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE))) {
return 1;
}
if (Z_TYPE(c->value) < IS_OBJECT
if (Z_TYPE(c->value) < IS_ARRAY
&& !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) {
return 1;
} else if (Z_TYPE(c->value) == IS_ARRAY
&& !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)
&& array_is_const(Z_ARR(c->value))) {
return 1;
}
return 0;
}
Expand Down Expand Up @@ -1690,7 +1723,10 @@ static bool zend_try_ct_eval_class_const(zval *zv, zend_string *class_name, zend
c = &cc->value;

/* Substitute case-sensitive (or lowercase) persistent class constants */
if (Z_TYPE_P(c) < IS_OBJECT) {
if (Z_TYPE_P(c) < IS_ARRAY) {
ZVAL_COPY_OR_DUP(zv, c);
return 1;
} else if (Z_TYPE_P(c) == IS_ARRAY && array_is_const(Z_ARR_P(c))) {
ZVAL_COPY_OR_DUP(zv, c);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Expand Up @@ -17,7 +17,7 @@ dnl Basic autoconf initialization, generation of config.nice.
dnl ----------------------------------------------------------------------------

AC_PREREQ([2.68])
AC_INIT([PHP],[8.1.23-dev],[https://github.com/php/php-src/issues],[php],[https://www.php.net])
AC_INIT([PHP],[8.1.24-dev],[https://github.com/php/php-src/issues],[php],[https://www.php.net])
AC_CONFIG_SRCDIR([main/php_version.h])
AC_CONFIG_AUX_DIR([build])
AC_PRESERVE_HELP_ORDER
Expand Down
19 changes: 12 additions & 7 deletions ext/dom/document.c
Expand Up @@ -139,19 +139,22 @@ int dom_document_encoding_read(dom_object *obj, zval *retval)
zend_result dom_document_encoding_write(dom_object *obj, zval *newval)
{
xmlDoc *docp = (xmlDocPtr) dom_object_get_node(obj);
zend_string *str;
xmlCharEncodingHandlerPtr handler;

if (docp == NULL) {
php_dom_throw_error(INVALID_STATE_ERR, 1);
return FAILURE;
}

str = zval_try_get_string(newval);
if (UNEXPECTED(!str)) {
return FAILURE;
/* Typed property, can only be IS_STRING or IS_NULL. */
ZEND_ASSERT(Z_TYPE_P(newval) == IS_STRING || Z_TYPE_P(newval) == IS_NULL);

if (Z_TYPE_P(newval) == IS_NULL) {
goto invalid_encoding;
}

zend_string *str = Z_STR_P(newval);

handler = xmlFindCharEncodingHandler(ZSTR_VAL(str));

if (handler != NULL) {
Expand All @@ -161,12 +164,14 @@ zend_result dom_document_encoding_write(dom_object *obj, zval *newval)
}
docp->encoding = xmlStrdup((const xmlChar *) ZSTR_VAL(str));
} else {
zend_value_error("Invalid document encoding");
return FAILURE;
goto invalid_encoding;
}

zend_string_release_ex(str, 0);
return SUCCESS;

invalid_encoding:
zend_value_error("Invalid document encoding");
return FAILURE;
}

/* }}} */
Expand Down
38 changes: 38 additions & 0 deletions ext/dom/tests/gh12002.phpt
@@ -0,0 +1,38 @@
--TEST--
GH-12002 (DOMDocument::encoding memory leak with invalid encoding)
--EXTENSIONS--
dom
--FILE--
<?php

function make_nonconst(string $x) {
// Defeat SCCP, even with inlining
return str_repeat($x, random_int(1, 1));
}

$dom = new DOMDocument();
$dom->encoding = make_nonconst('utf-8');
var_dump($dom->encoding);
try {
$dom->encoding = make_nonconst('foobar');
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
var_dump($dom->encoding);
$dom->encoding = make_nonconst('utf-16le');
var_dump($dom->encoding);
try {
$dom->encoding = NULL;
} catch (ValueError $e) {
echo $e->getMessage(), "\n";
}
var_dump($dom->encoding);

?>
--EXPECT--
string(5) "utf-8"
Invalid document encoding
string(5) "utf-8"
string(8) "utf-16le"
Invalid document encoding
string(8) "utf-16le"

0 comments on commit cfc659a

Please sign in to comment.