Skip to content

Commit 7779d19

Browse files
committed
Fix Calendar::createInstance double-free of the adopted TimeZone
ICU 57+ Calendar::createInstance wraps the TimeZone in a LocalPointer and deletes it when the calendar cannot be created. PHP deleted the same pointer again on that failure. Drop the extra delete in createInstance and fromDateTime.
1 parent e5623ea commit 7779d19

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ PHP NEWS
2020
left busy for the next fetch, and rows delivered from a result another
2121
statement took over. (KentarouTakeda)
2222

23+
- Intl:
24+
. Fixed a double-free when Calendar::createInstance() or
25+
IntlCalendar::fromDateTime() fails after adopting a TimeZone. (iliaal)
26+
2327
- Phar:
2428
. Fixed Phar archives being automatically detected when ".phar" only occurs
2529
in a directory name or is not a filename extension in an included file's

ext/intl/calendar/calendar_methods.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ PHP_INTL_FUNCTION_WITH_ERROR_RESET(intlcal_create_instance)
9696
Calendar *cal = Calendar::createInstance(timeZone,
9797
Locale::createFromName(locale_str), status);
9898
if (UNEXPECTED(cal == NULL)) {
99-
delete timeZone;
10099
intl_error_set(NULL, status, "Error creating ICU Calendar object");
101100
RETURN_NULL();
102101
}
@@ -1073,7 +1072,6 @@ PHP_INTL_FUNCTION_WITH_ERROR_RESET(intlcal_from_date_time)
10731072
cal = Calendar::createInstance(timeZone,
10741073
Locale::createFromName(locale_str), status);
10751074
if (UNEXPECTED(cal == NULL)) {
1076-
delete timeZone;
10771075
intl_error_set(NULL, status,
10781076
"error creating ICU Calendar object");
10791077
goto error;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
IntlCalendar::createInstance() and fromDateTime() adopt the TimeZone
3+
--EXTENSIONS--
4+
intl
5+
--INI--
6+
date.timezone=UTC
7+
--FILE--
8+
<?php
9+
10+
$cal = IntlCalendar::createInstance('Europe/Amsterdam', 'en_US');
11+
echo $cal->getTimeZone()->getID(), "\n";
12+
echo $cal->getType(), "\n";
13+
14+
$dt = new DateTime('2024-01-15 12:00:00', new DateTimeZone('America/New_York'));
15+
$cal2 = IntlCalendar::fromDateTime($dt, 'en_US');
16+
echo $cal2->getTimeZone()->getID(), "\n";
17+
echo $cal2->getType(), "\n";
18+
19+
?>
20+
--EXPECT--
21+
Europe/Amsterdam
22+
gregorian
23+
America/New_York
24+
gregorian

0 commit comments

Comments
 (0)