Skip to content

Commit 84c4336

Browse files
committedSep 21, 2023
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. Close GH-12245
1 parent da6097f commit 84c4336

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed
 

‎NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ PHP NEWS
1515
. Fixed bug GH-12186 (segfault copying/cloning a finalized HashContext).
1616
(MaxSem)
1717

18+
- Intl:
19+
. Fixed bug GH-12243 (segfault on IntlDateFormatter::construct).
20+
(David Carlier)
21+
22+
1823
- PCRE:
1924
. Fixed bug GH-11956 (Backport upstream fix, PCRE regular expressions with
2025
JIT enabled gives different result). (nielsdos)

‎ext/intl/dateformat/dateformat_create.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,11 @@ static zend_result datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_error_handlin
9999
}
100100
if (!INTL_UDATE_FMT_OK(time_type)) {
101101
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: invalid time format style", 0);
102-
return FAILURE;
102+
return FAILURE;
103+
}
104+
if (date_type == UDAT_PATTERN && time_type != UDAT_PATTERN) {
105+
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: time format must be UDAT_PATTERN if date format is UDAT_PATTERN", 0);
106+
return FAILURE;
103107
}
104108

105109
INTL_CHECK_LOCALE_LEN_OR_FAILURE(locale_len);

‎ext/intl/tests/gh12243.phpt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
GitHub #12043 segfault with IntlDateFormatter::dateType where it equals to UDAT_PATTERN (icu 50) but
3+
IntldateFormatter::timeType needs to be set as such.
4+
--EXTENSIONS--
5+
intl
6+
--FILE--
7+
<?php
8+
9+
$datetime = new \DateTime('2017-05-12 23:11:00 GMT+2');
10+
static $UDAT_PATTERN = -2;
11+
12+
try {
13+
new IntlDateFormatter(
14+
locale: 'en',
15+
dateType: $UDAT_PATTERN,
16+
timeType: 0,
17+
timezone: $datetime->getTimezone(),
18+
);
19+
} catch (\IntlException $e) {
20+
echo $e->getMessage();
21+
}
22+
23+
--EXPECT--
24+
datefmt_create: time format must be UDAT_PATTERN if date format is UDAT_PATTERN: U_ILLEGAL_ARGUMENT_ERROR

0 commit comments

Comments
 (0)