From 2f9d3f9530e8f8ec05a61f03c32a23c25af7ec18 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 19 Sep 2023 18:47:29 +0100 Subject: [PATCH] Fix GH-12243, segfault on IntlDateFormatter::construct with dateType set to UDAT_PATTERN but not timeType. udat_open expects its timeStyle's argument to be set to UDAT_PATTERN when dateStyle is, regardless if there an actual pattern or not. --- ext/intl/dateformat/dateformat_create.cpp | 6 +++++- ext/intl/tests/gh12243.phpt | 24 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 ext/intl/tests/gh12243.phpt diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index 58867746ef0ca..50e0bd75b7e61 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -99,7 +99,11 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin } if (!INTL_UDATE_FMT_OK(time_type)) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: invalid time format style", 0); -return FAILURE; + return FAILURE; + } + if (date_type == UDAT_PATTERN && time_type != UDAT_PATTERN) { + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: time format must be UDAT_PATTERN if date format is UDAT_PATTERN", 0); + return FAILURE; } INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len); diff --git a/ext/intl/tests/gh12243.phpt b/ext/intl/tests/gh12243.phpt new file mode 100644 index 0000000000000..80fb41032f343 --- /dev/null +++ b/ext/intl/tests/gh12243.phpt @@ -0,0 +1,24 @@ +--TEST-- +GitHub #12043 segfault with IntlDateFormatter::dateType where it equals to UDAT_PATTERN (icu 50) but +IntldateFormatter::timeType needs to be set as such. +--EXTENSIONS-- +intl +--FILE-- +getTimezone(), + ); +} catch (\IntlException $e) { + echo $e->getMessage(); +} + +--EXPECT-- +datefmt_create: time format must be UDAT_PATTERN if date format is UDAT_PATTERN: U_ILLEGAL_ARGUMENT_ERROR