Commit fac3db6e1bc for php
commit fac3db6e1bc23be15674d9c85bd96bf4172f1a31
Merge: 1c00fbbfa1e b5ddbf0f085
Author: Weilin Du <weilindu@php.net>
Date: Sun Nov 29 02:35:48 2026 +0800
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
ext/intl: Fix crash when formatting an uninitialized DateTime (#25878)
diff --cc ext/intl/common/common_date.cpp
index f2ca077554b,a635a4f1881..a84d0235a71
--- a/ext/intl/common/common_date.cpp
+++ b/ext/intl/common/common_date.cpp
@@@ -125,6 -127,17 +125,13 @@@ U_CFUNC zend_result intl_datetime_decom
return FAILURE;
}
- zval_ptr_dtor(&zfuncname);
- datetime = Z_PHPDATE_P(z);
+ if (!datetime->time) {
- spprintf(&message, 0, "%s: the %s object is not properly "
- "initialized", func, ZSTR_VAL(Z_OBJCE_P(z)->name));
- intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR,
- message, 1);
++ spprintf(&message, 0, "the %s object is not properly "
++ "initialized", ZSTR_VAL(obj->ce->name));
++ intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR, message);
+ efree(message);
+ return FAILURE;
+ }
*millis = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval) + (datetime->time->us / 1000);
}
diff --cc ext/intl/tests/dateformat_uninitialized_datetime_subclass.phpt
index 00000000000,fb0e728e487..444ce4194e5
mode 000000,100644..100644
--- a/ext/intl/tests/dateformat_uninitialized_datetime_subclass.phpt
+++ b/ext/intl/tests/dateformat_uninitialized_datetime_subclass.phpt
@@@ -1,0 -1,33 +1,33 @@@
+ --TEST--
+ intl_datetime_decompose() rejects uninitialized DateTime subclass overriding getTimestamp()
+ --EXTENSIONS--
+ intl
+ --FILE--
+ <?php
+
+ class UninitDateTime extends DateTime {
+ public function __construct() {}
+ public function getTimestamp(): int {
+ return 0;
+ }
+ }
+
+ $dt = new UninitDateTime();
+
+ var_dump(IntlDateFormatter::formatObject($dt));
+ var_dump(intl_get_error_message());
+
+ $fmt = new IntlDateFormatter('en_US', IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, 'UTC');
+ var_dump($fmt->format($dt));
+ var_dump($fmt->getErrorMessage());
+
+ var_dump(MessageFormatter::formatMessage('en_US', '{0,date,short}', [$dt]));
+ var_dump(intl_get_error_message());
+ ?>
---EXPECTF--
++--EXPECT--
+ bool(false)
-string(%d) "%sthe UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR"
++string(114) "IntlDateFormatter::formatObject(): the UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR"
+ bool(false)
-string(%d) "%sthe UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR"
++string(108) "IntlDateFormatter::format(): the UninitDateTime object is not properly initialized: U_ILLEGAL_ARGUMENT_ERROR"
+ bool(false)
-string(83) "The argument for key '0' cannot be used as a date or time: U_ILLEGAL_ARGUMENT_ERROR"
++string(118) "MessageFormatter::formatMessage(): The argument for key '0' cannot be used as a date or time: U_ILLEGAL_ARGUMENT_ERROR"