Skip to content

Fix GH-12243, segfault on IntlDateFormatter::construct with dateType #12245

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

Closed
Closed
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
6 changes: 5 additions & 1 deletion ext/intl/dateformat/dateformat_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions ext/intl/tests/gh12243.phpt
Original file line number Diff line number Diff line change
@@ -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--
<?php

$datetime = new \DateTime('2017-05-12 23:11:00 GMT+2');
static $UDAT_PATTERN = -2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like this constant should also be defined in the future?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed


try {
new IntlDateFormatter(
locale: 'en',
dateType: $UDAT_PATTERN,
timeType: 0,
timezone: $datetime->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