Skip to content

ext/intl: timezone using fast ZPP and fixing SpoofChecker #14415

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

Merged
merged 1 commit into from
Jun 1, 2024
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
4 changes: 2 additions & 2 deletions ext/intl/spoofchecker/spoofchecker_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PHP_METHOD(Spoofchecker, isSuspicious)
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STRING(text, text_len)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_OR_NULL(error_code)
Z_PARAM_ZVAL(error_code)
ZEND_PARSE_PARAMETERS_END();

SPOOFCHECKER_METHOD_FETCH_OBJECT;
Expand Down Expand Up @@ -76,7 +76,7 @@ PHP_METHOD(Spoofchecker, areConfusable)
Z_PARAM_STRING(s1, s1_len)
Z_PARAM_STRING(s2, s2_len)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL_OR_NULL(error_code)
Z_PARAM_ZVAL(error_code)
ZEND_PARSE_PARAMETERS_END();

SPOOFCHECKER_METHOD_FETCH_OBJECT;
Expand Down
99 changes: 47 additions & 52 deletions ext/intl/timezone/timezone_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone)
size_t str_id_len;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &str_id, &str_id_len) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(str_id, str_id_len)
ZEND_PARSE_PARAMETERS_END();

UErrorCode status = UErrorCode();
UnicodeString id = UnicodeString();
Expand All @@ -76,10 +76,9 @@ U_CFUNC PHP_FUNCTION(intltz_from_date_time_zone)
php_timezone_obj *tzobj;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "O",
&zv_timezone, php_date_get_timezone_ce()) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_OBJECT_OF_CLASS(zv_timezone, php_date_get_timezone_ce())
ZEND_PARSE_PARAMETERS_END();

tzobj = Z_PHPTIMEZONE_P(zv_timezone);
if (!tzobj->initialized) {
Expand All @@ -102,9 +101,7 @@ U_CFUNC PHP_FUNCTION(intltz_create_default)
{
intl_error_reset(NULL);

if (zend_parse_parameters_none() == FAILURE) {
return;
}
ZEND_PARSE_PARAMETERS_NONE();

TimeZone *tz = TimeZone::createDefault();
timezone_object_construct(tz, return_value, 1);
Expand All @@ -114,9 +111,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_gmt)
{
intl_error_reset(NULL);

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_NONE();

timezone_object_construct(TimeZone::getGMT(), return_value, 0);
}
Expand All @@ -125,9 +120,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_unknown)
{
intl_error_reset(NULL);

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_NONE();

timezone_object_construct(&TimeZone::getUnknown(), return_value, 0);
}
Expand All @@ -140,9 +133,10 @@ U_CFUNC PHP_FUNCTION(intltz_create_enumeration)

/* double indirection to have the zend engine destroy the new zval that
* results from separation */
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z", &arg) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(0, 1)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(arg)
ZEND_PARSE_PARAMETERS_END();

if (arg == NULL || Z_TYPE_P(arg) == IS_NULL) {
se = TimeZone::createEnumeration();
Expand Down Expand Up @@ -199,10 +193,9 @@ U_CFUNC PHP_FUNCTION(intltz_count_equivalent_ids)
size_t str_id_len;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
&str_id, &str_id_len) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(str_id, str_id_len)
ZEND_PARSE_PARAMETERS_END();

UErrorCode status = UErrorCode();
UnicodeString id = UnicodeString();
Expand All @@ -221,17 +214,19 @@ U_CFUNC PHP_FUNCTION(intltz_create_time_zone_id_enumeration)
zend_long zoneType,
offset_arg;
char *region = NULL;
size_t region_len = 0;
size_t region_len = 0;
int32_t offset,
*offsetp = NULL;
bool arg3isnull = 1;

intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "l|s!l!",
&zoneType, &region, &region_len, &offset_arg, &arg3isnull) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_LONG(zoneType)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(region, region_len)
Z_PARAM_LONG_OR_NULL(offset_arg, arg3isnull)
ZEND_PARSE_PARAMETERS_END();

if (zoneType != UCAL_ZONE_TYPE_ANY && zoneType != UCAL_ZONE_TYPE_CANONICAL
&& zoneType != UCAL_ZONE_TYPE_CANONICAL_LOCATION) {
Expand Down Expand Up @@ -266,10 +261,11 @@ U_CFUNC PHP_FUNCTION(intltz_get_canonical_id)
zval *is_systemid = NULL;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|z",
&str_id, &str_id_len, &is_systemid) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STRING(str_id, str_id_len)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(is_systemid)
ZEND_PARSE_PARAMETERS_END();

UErrorCode status = UErrorCode();
UnicodeString id;
Expand Down Expand Up @@ -303,10 +299,9 @@ U_CFUNC PHP_FUNCTION(intltz_get_region)
char outbuf[3];
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
&str_id, &str_id_len) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(str_id, str_id_len)
ZEND_PARSE_PARAMETERS_END();

UErrorCode status = UErrorCode();
UnicodeString id;
Expand All @@ -326,9 +321,7 @@ U_CFUNC PHP_FUNCTION(intltz_get_tz_data_version)
{
intl_error_reset(NULL);

if (zend_parse_parameters_none() == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_NONE();

UErrorCode status = UErrorCode();
const char *res = TimeZone::getTZDataVersion(status);
Expand All @@ -344,9 +337,10 @@ U_CFUNC PHP_FUNCTION(intltz_get_equivalent_id)
zend_long index;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &str_id, &str_id_len, &index) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_STRING(str_id, str_id_len)
Z_PARAM_LONG(index)
ZEND_PARSE_PARAMETERS_END();

if (UNEXPECTED(index < (zend_long)INT32_MIN || index > (zend_long)INT32_MAX)) {
RETURN_FALSE;
Expand Down Expand Up @@ -375,10 +369,9 @@ U_CFUNC PHP_FUNCTION(intltz_get_iana_id)
size_t str_id_len;
intl_error_reset(NULL);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "s",
&str_id, &str_id_len) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STRING(str_id, str_id_len)
ZEND_PARSE_PARAMETERS_END();

UErrorCode status = UErrorCode();
UnicodeString id;
Expand Down Expand Up @@ -635,9 +628,9 @@ U_CFUNC PHP_FUNCTION(intltz_get_windows_id)
UnicodeString uID, uWinID;
UErrorCode error;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &id) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_STR(id)
ZEND_PARSE_PARAMETERS_END();

error = U_ZERO_ERROR;
if (intl_stringFromChar(uID, id->val, id->len, &error) == FAILURE) {
Expand Down Expand Up @@ -671,9 +664,11 @@ U_CFUNC PHP_FUNCTION(intltz_get_id_for_windows_id)
UnicodeString uWinID, uID;
UErrorCode error;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|S!", &winID, &region) == FAILURE) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(winID)
Z_PARAM_OPTIONAL
Z_PARAM_STR_OR_NULL(region)
ZEND_PARSE_PARAMETERS_END();

error = U_ZERO_ERROR;
if (intl_stringFromChar(uWinID, winID->val, winID->len, &error) == FAILURE) {
Expand Down
Loading