Skip to content
Merged
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
9 changes: 9 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ PHP NEWS
className/classList writes and attribute removals. (Ilia Alshanetsky)

- Intl:
. Fixed grapheme_strpos() and grapheme_strrpos() with an empty needle
returning UTF-16 offsets instead of grapheme offsets. (Ilia Alshanetsky)
. Fixed a memory leak when dumping IntlCalendar instances. (Ilia Alshanetsky)
. Fixed Collator::sortWithSortKeys() allocating fixed 2MiB buffers
regardless of array size. (Ilia Alshanetsky)
Expand All @@ -22,6 +24,13 @@ PHP NEWS
read. (iliaal)
. Fixed a use-after-free when IntlRuleBasedBreakIterator is constructed
from compiled rules. (iliaal)
. Fixed Spoofchecker methods not recording the ICU error code when an ICU
call fails. (Ilia Alshanetsky)

- MBString:
. Fixed mb_ereg_replace() emitting a NUL or out-of-bounds bytes in the
replacement when a \k<name> backref has no closing delimiter.
(Ilia Alshanetsky)

- PDO_PGSQL:
. Added Pdo\Pgsql::ATTR_CHUNK_SIZE to fetch a result set in chunks of the
Expand Down
67 changes: 38 additions & 29 deletions ext/date/php_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -3258,7 +3258,12 @@ PHP_FUNCTION(date_format)
}
/* }}} */

static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{ */
typedef enum {
PHP_DATE_MODIFY_WARNING,
PHP_DATE_MODIFY_THROW
} php_date_modify_error_mode;

static bool php_date_modify(zval *object, char *modify, size_t modify_len, const php_date_modify_error_mode error_mode) /* {{{ */
{
php_date_obj *dateobj;
timelib_time *tmp_time;
Expand All @@ -3278,10 +3283,22 @@ static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{

if (err && err->error_count) {
/* spit out the first library error message, at least */
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", modify,
err->error_messages[0].position,
err->error_messages[0].character ? err->error_messages[0].character : ' ',
err->error_messages[0].message);
if (error_mode == PHP_DATE_MODIFY_THROW) {
zend_string *func_name = get_active_function_or_method_name();
zend_throw_exception_ex(date_ce_date_malformed_string_exception, 0,
"%s(): Failed to parse time string (%s) at position %d (%c): %s",
ZSTR_VAL(func_name),
modify,
err->error_messages[0].position,
err->error_messages[0].character ? err->error_messages[0].character : ' ',
err->error_messages[0].message);
zend_string_release_ex(func_name, false);
} else {
php_error_docref(NULL, E_WARNING, "Failed to parse time string (%s) at position %d (%c): %s", modify,
err->error_messages[0].position,
err->error_messages[0].character ? err->error_messages[0].character : ' ',
err->error_messages[0].message);
}
timelib_time_dtor(tmp_time);
return false;
}
Expand Down Expand Up @@ -3350,7 +3367,7 @@ PHP_FUNCTION(date_modify)
RETURN_THROWS();
}

if (!php_date_modify(object, modify, modify_len)) {
if (!php_date_modify(object, modify, modify_len, PHP_DATE_MODIFY_WARNING)) {
RETURN_FALSE;
}

Expand All @@ -3364,21 +3381,16 @@ PHP_METHOD(DateTime, modify)
zval *object;
char *modify;
size_t modify_len;
zend_error_handling zeh;

object = ZEND_THIS;
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(modify, modify_len)
ZEND_PARSE_PARAMETERS_END();

zend_replace_error_handling(EH_THROW, date_ce_date_malformed_string_exception, &zeh);
if (!php_date_modify(object, modify, modify_len)) {
zend_restore_error_handling(&zeh);
if (!php_date_modify(object, modify, modify_len, PHP_DATE_MODIFY_THROW)) {
RETURN_THROWS();
}

zend_restore_error_handling(&zeh);

RETURN_OBJ_COPY(Z_OBJ_P(object));
}
/* }}} */
Expand All @@ -3389,7 +3401,6 @@ PHP_METHOD(DateTimeImmutable, modify)
zval *object, new_object;
char *modify;
size_t modify_len;
zend_error_handling zeh;

object = ZEND_THIS;
ZEND_PARSE_PARAMETERS_START(1, 1)
Expand All @@ -3398,15 +3409,11 @@ PHP_METHOD(DateTimeImmutable, modify)

date_clone_immutable(object, &new_object);

zend_replace_error_handling(EH_THROW, date_ce_date_malformed_string_exception, &zeh);
if (!php_date_modify(&new_object, modify, modify_len)) {
if (!php_date_modify(&new_object, modify, modify_len, PHP_DATE_MODIFY_THROW)) {
zval_ptr_dtor(&new_object);
zend_restore_error_handling(&zeh);
RETURN_THROWS();
}

zend_restore_error_handling(&zeh);

RETURN_OBJ(Z_OBJ(new_object));
}
/* }}} */
Expand Down Expand Up @@ -3463,7 +3470,7 @@ PHP_METHOD(DateTimeImmutable, add)
}
/* }}} */

static void php_date_sub(zval *object, zval *interval, zval *return_value) /* {{{ */
static void php_date_sub(zval *object, zval *interval, zval *return_value, const bool should_throw) /* {{{ */
{
php_date_obj *dateobj;
php_interval_obj *intobj;
Expand All @@ -3475,7 +3482,15 @@ static void php_date_sub(zval *object, zval *interval, zval *return_value) /* {{
DATE_CHECK_INITIALIZED(intobj->initialized, Z_OBJCE_P(interval));

if (intobj->diff->have_weekday_relative || intobj->diff->have_special_relative) {
php_error_docref(NULL, E_WARNING, "Only non-special relative time specifications are supported for subtraction");
if (should_throw) {
zend_string *func_name = get_active_function_or_method_name();
zend_throw_exception_ex(date_ce_date_invalid_operation_exception, 0,
"%s(): Only non-special relative time specifications are supported for subtraction",
ZSTR_VAL(func_name));
zend_string_release_ex(func_name, false);
} else {
php_error_docref(NULL, E_WARNING, "Only non-special relative time specifications are supported for subtraction");
}
return;
}

Expand All @@ -3497,7 +3512,7 @@ PHP_FUNCTION(date_sub)
RETURN_THROWS();
}

php_date_sub(object, interval, return_value);
php_date_sub(object, interval, return_value, false);
RETURN_OBJ_COPY(Z_OBJ_P(object));
}
/* }}} */
Expand All @@ -3506,15 +3521,12 @@ PHP_FUNCTION(date_sub)
PHP_METHOD(DateTime, sub)
{
zval *object, *interval;
zend_error_handling zeh;

if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "OO", &object, date_ce_date, &interval, date_ce_interval) == FAILURE) {
RETURN_THROWS();
}

zend_replace_error_handling(EH_THROW, date_ce_date_invalid_operation_exception, &zeh);
php_date_sub(object, interval, return_value);
zend_restore_error_handling(&zeh);
php_date_sub(object, interval, return_value, true);

RETURN_OBJ_COPY(Z_OBJ_P(object));
}
Expand All @@ -3524,7 +3536,6 @@ PHP_METHOD(DateTime, sub)
PHP_METHOD(DateTimeImmutable, sub)
{
zval *object, *interval, new_object;
zend_error_handling zeh;

object = ZEND_THIS;
ZEND_PARSE_PARAMETERS_START(1, 1)
Expand All @@ -3533,9 +3544,7 @@ PHP_METHOD(DateTimeImmutable, sub)

date_clone_immutable(object, &new_object);

zend_replace_error_handling(EH_THROW, date_ce_date_invalid_operation_exception, &zeh);
php_date_sub(&new_object, interval, return_value);
zend_restore_error_handling(&zeh);
php_date_sub(&new_object, interval, return_value, true);

RETURN_OBJ(Z_OBJ(new_object));
}
Expand Down
6 changes: 5 additions & 1 deletion ext/intl/grapheme/grapheme_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ U_CFUNC int32_t grapheme_strpos_utf16(char *haystack, size_t haystack_len, char
ret_pos = -1;
goto finish;
}
ret_pos = last && offset >= 0 ? uhaystack_len : offset_pos;
if (last && offset >= 0) {
ret_pos = grapheme_count_graphemes(bi, uhaystack, uhaystack_len);
} else {
ret_pos = grapheme_count_graphemes(bi, uhaystack, offset_pos);
}
goto finish;
}

Expand Down
6 changes: 6 additions & 0 deletions ext/intl/spoofchecker/spoofchecker_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ U_CFUNC PHP_METHOD(Spoofchecker, isSuspicious)
ret = intl_icu_compat_uspoof_check_utf8(co->uspoof, ZSTR_VAL(text), ZSTR_LEN(text), co->uspoofres, SPOOFCHECKER_ERROR_CODE_P(co));

if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));

if (intl_icu_compat_uspoof_check_result_mismatch(co->uspoofres, ret, &errmask, SPOOFCHECKER_ERROR_CODE_P(co))) {
Expand Down Expand Up @@ -83,6 +84,7 @@ U_CFUNC PHP_METHOD(Spoofchecker, areConfusable)
ret = uspoof_areConfusableUTF8(co->uspoof, ZSTR_VAL(s1), (int32_t)ZSTR_LEN(s1), ZSTR_VAL(s2), (int32_t)ZSTR_LEN(s2), SPOOFCHECKER_ERROR_CODE_P(co));
}
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
RETURN_TRUE;
}
Expand All @@ -109,6 +111,7 @@ U_CFUNC PHP_METHOD(Spoofchecker, setAllowedLocales)
uspoof_setAllowedLocales(co->uspoof, ZSTR_VAL(locales), SPOOFCHECKER_ERROR_CODE_P(co));

if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
return;
}
Expand All @@ -130,6 +133,7 @@ U_CFUNC PHP_METHOD(Spoofchecker, setChecks)
uspoof_setChecks(co->uspoof, checks, SPOOFCHECKER_ERROR_CODE_P(co));

if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
}
}
Expand Down Expand Up @@ -220,6 +224,7 @@ U_CFUNC PHP_METHOD(Spoofchecker, setAllowedChars)
efree(upattern);

if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
}
}
Expand Down Expand Up @@ -355,6 +360,7 @@ U_CFUNC PHP_METHOD(Spoofchecker, areBidiConfusable)
ret = uspoof_areBidiConfusableUTF8(co->uspoof, (UBiDiDirection)direction, ZSTR_VAL(s1), (int32_t)ZSTR_LEN(s1), ZSTR_VAL(s2), (int32_t)ZSTR_LEN(s2), SPOOFCHECKER_ERROR_CODE_P(co));
}
if (U_FAILURE(SPOOFCHECKER_ERROR_CODE(co))) {
intl_error_set_code(NULL, SPOOFCHECKER_ERROR_CODE(co));
php_error_docref(NULL, E_WARNING, "(%d) %s", SPOOFCHECKER_ERROR_CODE(co), u_errorName(SPOOFCHECKER_ERROR_CODE(co)));
RETURN_TRUE;
}
Expand Down
34 changes: 34 additions & 0 deletions ext/intl/tests/grapheme_empty_offset_multibyte.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
grapheme_strpos() family with empty needle and offset on multi-code-unit graphemes
--EXTENSIONS--
intl
--FILE--
<?php

var_dump(grapheme_strpos("😀x", ""));
var_dump(grapheme_strpos("😀x", "", 0));
var_dump(grapheme_strpos("😀x", "", 1));
var_dump(grapheme_stripos("😀x", "", 1));
var_dump(grapheme_strpos("😀x", "", -1));
var_dump(grapheme_strrpos("😀x", ""));
var_dump(grapheme_strrpos("😀x", "", 1));
var_dump(grapheme_strripos("😀x", "", 1));
var_dump(grapheme_strrpos("😀x", "", -1));
try {
var_dump(grapheme_strpos("😀x", "", 5));
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}

?>
--EXPECT--
int(0)
int(0)
int(1)
int(1)
int(1)
int(2)
int(2)
int(2)
int(1)
ValueError: grapheme_strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack)
18 changes: 18 additions & 0 deletions ext/intl/tests/spoofchecker_setchecks_error_code.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Spoofchecker::setChecks() records the ICU error code
--EXTENSIONS--
intl
--SKIPIF--
<?php if (!class_exists("Spoofchecker")) print 'skip'; ?>
--FILE--
<?php

$s = new Spoofchecker();
$s->setChecks(1 << 20);
var_dump(intl_get_error_code(), intl_get_error_message());

?>
--EXPECTF--
Warning: Spoofchecker::setChecks(): (1) U_ILLEGAL_ARGUMENT_ERROR in %s on line %d
int(1)
string(24) "U_ILLEGAL_ARGUMENT_ERROR"
5 changes: 3 additions & 2 deletions ext/mbstring/php_mbregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ static inline void mb_regex_substitute(
clen = (int) php_mb_mbchar_bytes(++p, enc);
if (clen != 1 || p == eos || (p[0] != '<' && p[0] != '\'')) {
/* not a backref delimiter */
p += clen;
p = MIN(p + clen, eos);
smart_str_appendl(pbuf, sp, p - sp);
continue;
}
Expand All @@ -789,12 +789,13 @@ static inline void mb_regex_substitute(
if (maybe_num && !isdigit((unsigned char)name_end[0])) maybe_num = 0;
name_end++;
}
p = name_end + 1;
if (name_end - name < 1 || name_end >= eos) {
/* the backref was empty or we failed to find the end delimiter */
p = MIN(name_end + 1, eos);
smart_str_appendl(pbuf, sp, p - sp);
continue;
}
p = name_end + 1;
/* we have either a name or a number */
if (maybe_num) {
if (!onig_noname_group_capture_is_active(regexp)) {
Expand Down
27 changes: 27 additions & 0 deletions ext/mbstring/tests/mb_ereg_replace_kname_unterminated_nul.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
mb_ereg_replace() with unterminated \k<name> backref must not embed a NUL byte
--EXTENSIONS--
mbstring
--FILE--
<?php
var_dump(bin2hex(mb_ereg_replace('(\d+)', '\k<num', '123')));
var_dump(bin2hex(mb_ereg_replace('(\d+)', "\\k'num", '123')));
var_dump(bin2hex(mb_ereg_replace('(x)(y)', 'a\k<n', 'xy')));
var_dump(bin2hex(mb_ereg_replace('(\d+)', "a\\k\xF0", '123')));
var_dump(bin2hex(mb_ereg_replace('(\d+)', "\\\\k\xE2\x82", '123')));
?>
--EXPECTF--
Deprecated: Function mb_ereg_replace() is deprecated since 8.6, because the underlying library is no longer maintained in %s on line %d
string(12) "5c6b3c6e756d"

Deprecated: Function mb_ereg_replace() is deprecated since 8.6, because the underlying library is no longer maintained in %s on line %d
string(12) "5c6b276e756d"

Deprecated: Function mb_ereg_replace() is deprecated since 8.6, because the underlying library is no longer maintained in %s on line %d
string(10) "615c6b3c6e"

Deprecated: Function mb_ereg_replace() is deprecated since 8.6, because the underlying library is no longer maintained in %s on line %d
string(8) "615c6bf0"

Deprecated: Function mb_ereg_replace() is deprecated since 8.6, because the underlying library is no longer maintained in %s on line %d
string(10) "5c5c6be282"
1 change: 0 additions & 1 deletion ext/openssl/tests/CONFLICTS

This file was deleted.

14 changes: 13 additions & 1 deletion ext/pdo_odbc/odbc_stmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum pdo_odbc_conv_result {

static int pdo_odbc_sqltype_is_unicode(pdo_odbc_stmt *S, SQLSMALLINT sqltype)
{
#ifdef PHP_WIN32
if (!S->assume_utf8) return 0;
switch (sqltype) {
#ifdef SQL_WCHAR
Expand All @@ -52,6 +53,9 @@ static int pdo_odbc_sqltype_is_unicode(pdo_odbc_stmt *S, SQLSMALLINT sqltype)
default:
return 0;
}
#else
return 0;
#endif
}

static int pdo_odbc_utf82ucs2(pdo_stmt_t *stmt, int is_unicode, const char *buf,
Expand Down Expand Up @@ -544,7 +548,15 @@ static int odbc_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *p
break;
}
} else {
P->len = SQL_LEN_DATA_AT_EXEC(Z_STRLEN_P(parameter));
zend_ulong ulen;
if (pdo_odbc_utf82ucs2(stmt, P->is_unicode,
Z_STRVAL_P(parameter),
Z_STRLEN_P(parameter),
&ulen) == PDO_ODBC_CONV_OK) {
P->len = SQL_LEN_DATA_AT_EXEC(ulen);
} else {
P->len = SQL_LEN_DATA_AT_EXEC(Z_STRLEN_P(parameter));
}
}
}
return 1;
Expand Down
Loading
Loading